Python-Ref > Data structures > Sets > Set and list conversion
 
 

<-^^->
Klíčová slova
Moduly
Knihovní funkce

Set and list conversion

Expand/Shrink
Zdroj: (sets6-1.py)
  1   list1 = [1,3,32,4,2,4,2,3]
  2   set1 = set( list1)
  3   print set1
  4   
  5   list2 = list( set1)
  6   print list2
  7   
  8   # list with unique values from a list
  9   xs = [1,1,1,1,2,3,4,2,21,1,1,1,3,4,45,5]
 10   unique = list( set( xs))
 11   print unique
stdout:
set([32, 1, 2, 3, 4])
[32, 1, 2, 3, 4]
[1, 2, 3, 4, 5, 45, 21]
Doba běhu: 19.0 ms