My dict is as follows:
the_dict = {'1': 2,
'2': 4,
'3': 3,
'8': 3,
'9': 3,
'10': 4,
'14': 4}
I need to multiply the keys by the values to create a long flat list. My attempt is as follows but it screws up the 10 and 14:
new_target = []
for k, v in zip(the_dict.keys(), the_dict.values()):
new_target += list(k*v)
This code produces:
['1', '1', '2', '2', '2', '2', '3', '3', '3', '8', '8', '8', '9', '9', '9', '1', '0', '1', '0', '1', '0', '1', '0', '1', '4', '1', '4', '1', '4', '1', '4']
That code comes close, but it doesn't work due to the following behavior on the 10 and 14; list("10" *2) produces ['1', '0', '1', '0'] instead of the desired ['10', '10'].
How do I create the desired list?