Friday, February 11, 2011

python: Listから重複を無くす

>>> L = [1, 2, 1, 3, 2, 4, 5]
>>> set(L)
{1, 2, 3, 4, 5}
>>> L = list(set(L)) # Remove duplicates
>>> L
[1, 2, 3, 4, 5]

Lerning Python 4th P138

No comments:

Post a Comment