Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Getting rid of duplicate items in a list
- The trick is to temporarly convert the list in into a dictionnary:
- >>> mylist = [3,5,8,5,3,12]
- >>> print dict().fromkeys(mylist).keys()
- [8, 3, 12, 5]
- >>>
- Since Python 2.5, you can also use sets:
- >>> mylist = [3,5,8,5,3,12]
- >>> print list(set(mylist))
- [8, 3, 12, 5]
- >>>
Advertisement
Add Comment
Please, Sign In to add comment