Basic question about generators on a dict of lists

Thank you, it works. Now I would like to make it more readable by myself instead of copy/pasting, because I am not comfortable with nesting functions... This is my first contact with generators :)

The code below, inspired by your idea works.

I just need to make the dict construction more elegant (I will have around 10 keys/lists in prod).. I struggle with the dict comprehension and zip, can you help me construct the dict of generators ? Thanks

def my_gen(l):
    for item in l:
        yield item

grocery_list = ["spam", "ham", "banana", "apple pie", "maple syrup"]
number_list = [2, 5, 8, 10, 1, 5, 9, 8]

g1 = my_gen(grocery_list)
g2 = my_gen(number_list)

dico_gen = {'groceries' : g1 , 'numbers' : g2 }

print(next(dico_gen['groceries']))
print(next(dico_gen['numbers']))
print(next(dico_gen['groceries']))
print(next(dico_gen['numbers']))
print(next(dico_gen['numbers']))
print(next(dico_gen['numbers']))
print(next(dico_gen['groceries']))
/r/learnpython Thread Parent