-2

I have a line of code that makes a list from a to z

possible_draws = list(string.ascii_lowercase)

and a user randomly draws 6 letters from inside (Can dupe)

People say that sample doesn't dupe, what should I do then?

user_numbers = random.sample(possible_draws, 6)

Then I print User_numbers

print(user_numbers)

To show the player what letters have been drawn.

But I don't know how to check if there are duplicates in

user_numbers

and if there are duplicates, how many duplicates are there?

*If there is more than 1 duplicate set, it would pick the one with more duplicates.

How could I do that?

Simon Choi
  • 15
  • 4

1 Answers1

0
user_numbers = ...  #Insert your list here


list3 = []
list3a = {}
for i in user_numbers:
    if i not in list3:
        list3.append(i)
    else:
        if i not in list3a:
            list3a[i] = 1
        else:
            list3a[i] += 1

I just used list3 & list3a here as they were handy in my IDE when double checking myself. It'll output a list with duplicates removed (list3) and the number of duplicates(not including original) in a dictionary in list3a

list3a can be sorted quite easily as per:

list3b = dict(sorted(list3a.items(), key=lambda item: item[1],reverse=True),)

and if your using Python 3.7+, then the highest repetitive number is given by:

next(iter(list3b))
Amiga500
  • 1,258
  • 1
  • 6
  • 11