What is pythononic way of slicing a set?

前端 未结 3 1048
渐次进展
渐次进展 2021-01-03 00:13

I have some list of data, for example

some_data = [1, 2, 4, 1, 6, 23, 3, 56, 6, 2, 3, 5, 6, 32, 2, 12, 5, 3, 2]

and i want to get unique va

3条回答
  •  借酒劲吻你
    2021-01-03 01:10

    You could try a simple set comprehension:

    some_data = [1, 2, 4, 1, 6, 23, 3, 56, 6, 2, 3, 5, 6, 32, 2, 12, 5, 3, 2]
    n = {x for i, x in enumerate(set(some_data)) if i < 5}
    print n
    

    Output:

    set([32, 1, 2, 3, 4])

提交回复
热议问题