Python Deduplication

Asked 1 years ago, Updated 1 years ago, 118 views

It's a lottery extraction. You have to extract it 6 times without duplicating it Please tell me how to sort by the most extracted numbers from the six printed lists...Please let me know

python list loops extract

2022-09-22 20:11

2 Answers

import random

numbers = list(range(1,46))
random.shuffle(numbers)
print( numbers[:6] )

It's a method of randomly picking 6 numbers between 1 and 45. We can do this six times. Find the most extracted number here.

from collections import Counter
Counter([1,2,3,4,5,5,5,5])

I think it'd be good to use that.


2022-09-22 20:11

I heard that you use repetitive sentences

import random
from collections import Counter

number_list = list(range(1, 46))
count = Counter()

for i in range(6):
    lotto = random.sample(number_list, 6) # Extract 6 from list
    count.update(lotto)

common = [m[0] for m in count.most_common(6)]

print(common)


2022-09-22 20:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.