사소한 Tip . 오류 해결법/python
[python] random.sample with ordering(랜덤 추출하면서 순서 유지)
Js.Y
2023. 8. 4. 08:56
728x90
반응형
Get random sample from list while maintaining ordering of items?
I have a sorted list, let say: (its not really just numbers, its a list of objects that are sorted with a complicated time consuming algorithm) mylist = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,9 , 10 ] ...
stackoverflow.com
sample_size = 4
sorted_sample = [
mylist[i] for i in sorted(random.sample(range(len(mylist)), sample_size))
]
728x90
반응형