Python Forum
Randomly assign values in List 1 to a value in List 2
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Randomly assign values in List 1 to a value in List 2
#5
there are plenty of possibilities, e.g.
from itertools import cycle
from collections import Counter
from random import shuffle

students = ['Joey', 'Henry', 'Daniel', 'James', 'Samantha', 'Jose', 'Salvator', 'Paul', 'Steve', 'Mary', 'Kyle', 'Marcus', 'Pat']
dates = ['Jan 6', 'Jan 8', 'Jan 10']

shuffle(students)
schedule = dict(zip(students, cycle(dates)))
print(schedule)
print(Counter(schedule.values()).most_common())
Output:
{'Steve': 'Jan 6', 'Mary': 'Jan 8', 'Kyle': 'Jan 10', 'Jose': 'Jan 6', 'Henry': 'Jan 8', 'Marcus': 'Jan 10', 'Paul': 'Jan 6', 'James': 'Jan 8', 'Salvator': 'Jan 10', 'Samantha': 'Jan 6', 'Joey': 'Jan 8', 'Pat': 'Jan 10', 'Daniel': 'Jan 6'} [('Jan 6', 5), ('Jan 8', 4), ('Jan 10', 4)]
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Randomly assign values in List 1 to a value in List 2 - by buran - Dec-11-2019, 04:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange behavior list of list mmhmjanssen 2 244 May-01-2024, 07:16 AM
Last Post: Gribouillis
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 328 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  pyaudio seems to randomly halt input. elpidiovaldez5 2 421 Jan-22-2024, 09:07 AM
Last Post: elpidiovaldez5
  Copying the order of another list with identical values gohanhango 7 1,204 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,300 Nov-03-2023, 05:35 PM
Last Post: huzzug
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,244 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Problem with code / audio is playing randomly, not matching csv requirements Daniel_kcr 2 665 Sep-07-2023, 05:09 PM
Last Post: deanhystad
  Comparing List values to get indexes Edward_ 7 1,237 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 1,594 May-01-2023, 09:06 PM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 947 Feb-23-2023, 02:21 PM
Last Post: sparkt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020