Beginners often encounter how to remove list The problem of repeating elements in . This problem may need to be solved in other languages for Circulation or something , And in the python Not in , It's simple , Only need to list As set Construct a set, And then set Conversion meeting list That's all right. .
The following code :
myList = list(set(myList))
Here is an example of how to use :
>>> myList = [1, 2, 3, 3, 2, 2, 4, 5, 5] >>> myList [1, 2, 3, 3, 2, 2, 4, 5, 5] >>> myList = list(set(myList)) >>> myList [1, 2, 3, 4, 5] >>>