Created
October 23, 2018 09:40
-
-
Save flowpoint/8233fb07eef0f1a1561c0f8c29b8a9d8 to your computer and use it in GitHub Desktop.
linear time list remove python, no correctness guarantee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def linear_list_remove(target, elems_to_remove): | |
''' careful, this is not always correct because hash collisions | |
removes list elements from list in O(1) ''' | |
mp = {} | |
for i in elems_to_remove: | |
mp[i] = 1 #remove linebreak | |
ret_list = [] | |
for i in target: | |
#print(mp.get(i)) | |
if mp.get(i, False): | |
ret_list += [i] | |
return ret_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment