Jun-06-2020, 10:46 PM
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