jeudi 28 juillet 2022

Generating a random number from highest count numbers in a list of tuples in Python

This really isn't an issue...more of a brain storming...

Let's say I have a list of tuples like so:

The second index of the tuple is a count of how many times the first index appeared in a dataset.

[(24, 11), (12, 10), (48, 10), (10, 9), (26, 9), (59, 9), (39, 9), (53, 9), (21, 9), (52, 9), (50, 9), (41, 8), (33, 8), (44, 8), (46, 8), (38, 8), (20, 8), (57, 8), (23, 7), (6, 7), (3, 7), (37, 7), (51, 7), (34, 6), (54, 6), (36, 6), (14, 6), (17, 6), (58, 6), (15, 6), (29, 6), (13, 5), (32, 5), (9, 5), (40, 5), (45, 5), (1, 5), (31, 5), (11, 5), (30, 5), (5, 5), (56, 5), (35, 5), (47, 5), (2, 4), (19, 4), (42, 4), (25, 4), (43, 4), (4, 4), (18, 4), (16, 4), (49, 4), (8, 4), (22, 4), (7, 4), (27, 4), (55, 3), (28, 2)]

As you can see there are multiples of the same number in the second index. Is there a way you could collect the first six of the counts and put them into another list?

For example collect all the 11, 10, 9, 8, 7 counts and so on and then generate a number of six in length from that collection.

I am trying to generate a random number from the 6 most common numbers.




Aucun commentaire:

Enregistrer un commentaire