Friday, June 23, 2017

Python : How to eliminate duplicate elements from a List

Duplicates elements from a List can be  removed by using list(set())


List containing duplicate elements:

name_list = ['Ram','Nidish','Ram','Veena','Krish']







Use list(set()) to remove duplicates,

name_list=list(set(name_list))








Run Environment: Python 2.7
Note: Set returns un-ordered list so list order would be lost.

No comments:

Post a Comment