something like
Otherwise
my_list= ['a','b','a','c','b'] my_dict = {'a':[3,2],'b':[4,5],'c':[1]} result = [my_dict[key].pop(0) for key in my_list] print(result)but it assumes all elements in my_list are present in my_dict.keys and there are enough elements in the respective list in the dict.
Otherwise
my_list= ['a','b','a','c','b'] my_dict = {'a':[3],'b':[4,5],'c':[1]} result = [] for key in my_list: try: result.append(my_dict[key].pop(0)) except (KeyError, IndexError): continue print(result)
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
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs