Skip to content

Instantly share code, notes, and snippets.

@flowpoint
Created October 23, 2018 09:40
Show Gist options
  • Save flowpoint/8233fb07eef0f1a1561c0f8c29b8a9d8 to your computer and use it in GitHub Desktop.
Save flowpoint/8233fb07eef0f1a1561c0f8c29b8a9d8 to your computer and use it in GitHub Desktop.
linear time list remove python, no correctness guarantee
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