In Python, how to remove duplicates from lists ?
The best option to remove duplicates from a list is to convert the list in set
(which cannot contain duplicate), then to convert back to list:
myList = [5, 1, 1, 2, 5, 6, 3, 4, 4, 4, 2]
# list -> set -> list
myList = list(set(myList))
# [1, 2, 3, 4, 5, 6]
print (myList)
Set if one of the 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage.
The best option to remove duplicates from a list is to convert the list in set
(which cannot contain duplicate), then to convert back to list:
myList = [5, 1, 1, 2, 5, 6, 3, 4, 4, 4, 2]
# list -> set -> list
myList = list(set(myList))
# [1, 2, 3, 4, 5, 6]
print (myList)
Set if one of the 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage.
The best option to remove duplicates from a list is to convert the list in set
(which cannot contain duplicate), then to convert back to list:
myList = [5, 1, 1, 2, 5, 6, 3, 4, 4, 4, 2]
# list -> set -> list
myList = list(set(myList))
# [1, 2, 3, 4, 5, 6]
print (myList)
Set if one of the 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage.
The best option to remove duplicates from a list is to convert the list in set
(which cannot contain duplicate), thus to convert back to list:
myList = [5, 1, 1, 2, 5, 6, 3, 4, 4, 4, 2]
# list -> set -> list
myList = list(set(myList))
# [1, 2, 3, 4, 5, 6]
print (myList)
Set if one of the 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage.
The best option to remove duplicates from a list is to convert the list in set
(which cannot contain duplicate), thus to convert back to list:
myList = [5, 1, 1, 2, 5, 6, 3, 4, 4, 4, 2]
# list -> set -> list
myList = list(set(myList))
# [1, 2, 3, 4, 5, 6]
print (myList)
Set if one of the 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage.
# | ID | Query | URL | Count |
---|