What is pythononic way of slicing a set?

前端 未结 3 1065
渐次进展
渐次进展 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条回答
  •  Happy的楠姐
    2021-01-03 01:12

    You could sample the set

    import random
    set(random.sample(my_set, 5)) 
    

    The advantage of this you'll get different numbers each time

提交回复
热议问题