Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lists in tkinter
#3
I might create a separate generator. Then it could loop over the lists and randomly pick from each.

def rand_from_seq_lists():
    lists = [
              ['dog','cat','cow','horse','duck','bird'],
              ['Hippo', 'Bat', 'Fish', 'Whale', 'Bear', 'Monkey'],
            ]
    while True:
        for sublist in lists:
            yield random.choice(sublist)


picks = 4
gen = rand_from_seq_lists()
print(f"Here are {picks} choices, randomly from each list sequentially chosen.")
for _ in range(picks):
    print(next(gen))
Output:
Here are 4 choices, randomly from each list sequentially chosen. bird Bat horse Bear
Reply


Messages In This Thread
lists in tkinter - by erock - Jun-06-2020, 10:14 PM
RE: lists in tkinter - by menator01 - Jun-06-2020, 10:34 PM
RE: lists in tkinter - by bowlofred - Jun-06-2020, 10:46 PM
RE: lists in tkinter - by erock - Jun-06-2020, 11:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,493 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,371 Mar-20-2019, 08:01 PM
Last Post: stillsen

Forum Jump:

User Panel Messages

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