Python @ DjangoSpin

Python: Removing duplicate items from lists

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Removing duplicate items from lists in Python

Removing duplicate items from lists in Python

A simple way to remove duplicate items from a list is to cast it to a set, and then back to a list using the constructors of builtin set and list classes.

>>> aList = [1, 2, 3, 1, 2, 3, 4, 5]
>>> list( set(aList) )
[1, 2, 3, 4, 5]

See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply