I want to access or select the first number in counter using Python. So I have this code, that will run random number from 1 to 10 with 100 trials, then it will count the most frequent number that occured.
from collections import Counter
from random import choice
y = []
for x in [(choice([i for i in range(1,10) if i not in [0]])) for j in range(100)]:
y.append(x)
a = Counter(y)
b= a.most_common(1)
print(b)
I want to know that number so I need to select it alone. So for example, my output is
[(2, 17)]
2 is the most frequent number, so how I'm going to select that number from that structure type. Expected output:
2
Thanks for the help!