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
#8
Another one :p

import random

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

l = [students[i * Nstud:((i + 1) * Nstud)] for i in range(len(students) // Nstud)]
final = {date: l[i] for i, date in enumerate(dates)}

print(final)
Reply


Messages In This Thread
RE: Randomly assign values in List 1 to a value in List 2 - by BamBi25 - Dec-16-2019, 12:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 283 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  pyaudio seems to randomly halt input. elpidiovaldez5 2 372 Jan-22-2024, 09:07 AM
Last Post: elpidiovaldez5
  Copying the order of another list with identical values gohanhango 7 1,141 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,246 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,172 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Problem with code / audio is playing randomly, not matching csv requirements Daniel_kcr 2 633 Sep-07-2023, 05:09 PM
Last Post: deanhystad
  Comparing List values to get indexes Edward_ 7 1,161 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 1,542 May-01-2023, 09:06 PM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 920 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Adding values with reduce() function from the list of tuples kinimod 10 2,666 Jan-24-2023, 08:22 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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