Skip to content

Instantly share code, notes, and snippets.

@ungarst
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ungarst/153edccc8f61d7e161fc to your computer and use it in GitHub Desktop.
Save ungarst/153edccc8f61d7e161fc to your computer and use it in GitHub Desktop.
Case Insensitive Unique List
def unique_list(list):
u_list = []
[u_list.append(x) for x in list if x.lower() not in [y.lower() for y in u_list]]
return u_list
print (unique_list(["Welcome", "to", "COMPSCI101", "to", "wELcome"]))
# BETTER VERSION!!!
def unique_list(list):
return [list[i] for i in range(0,len(list)) if list[i].lower() not in [y.lower() for y in list[:i]]]
print (unique_list(["Welcome", "to", "COMPSCI101", "to", "wELcome"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment