Python set to list

后端 未结 7 1862
谎友^
谎友^ 2020-12-22 18:28

How can I convert a set to a list in Python? Using

a = set([\"Blah\", \"Hello\"])
a = list(a)

doesn\'t work. It gives me:

         


        
相关标签:
7条回答
  • 2020-12-22 19:25

    Try using combination of map and lambda functions:

    aList = map( lambda x: x, set ([1, 2, 6, 9, 0]) )
    

    It is very convenient approach if you have a set of numbers in string and you want to convert it to list of integers:

    aList = map( lambda x: int(x), set (['1', '2', '3', '7', '12']) )
    
    0 讨论(0)
提交回复
热议问题