|
Academic Work Personal
|
Python /
Removing duplicates
We want to remove duplicates from a list and keep the original order of the elements. If you convert the list to a set, then duplicates are removed, but you lose the order.
def remove_duplicates(li):
"""remove duplicates from a list by keeping the order"""
dict = {}
copy = []
for e in li:
if not dict.has_key(e):
copy.append(e)
dict[e] = 1
return copy
|
![]() anime | bash | blogs | bsd | c/c++ | c64 | calc | comics | convert | cube | del.icio.us | digg | east | eBooks | egeszseg | elite | firefox | flash | fun | games | gimp | google | groovy | hardware | hit&run | howto | java | javascript | knife | lang | latex | liferay | linux | lovecraft | magyar | maths | movies | music | p2p | perl | pdf | photoshop | php | pmwiki | prog | python | radio | recept | rts | scala | scene | sci-fi | scripting | security | shell | space | súlyos | telephone | torrente | translate | ubuntu | vim | wallpapers | webutils | wikis | windows Blogs and Dev. * Ubuntu Incident Places Debrecen | France | Hungary | Montreal | Nancy Notes Hobby Projects * Jabba's Codes Quick Links [ edit ] |