Monday, May 19, 2014

Remove duplicates from a list in Python

The python built in function 'set()' helps to remove the duplicates from a list.

consider an example:
>>> list1 = [1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> list1
[1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> set(list1)
set([1, 2, 3, 5, 6, 7, 8])
>>> list(set(list1))
[1, 2, 3, 5, 6, 7, 8]
>>>

Labels: , ,


0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

 
Twitter Facebook RSS YouTube Google
© 2014 | Distributed and Designed By Jasad Moozhiyan