In this function, I am trying to create a list which includes the keys of a dictionary multiplied by the value they are mapped to, value being a non-negative integer. My code gives me what I am looking for but treats every character of the keys(which are strings) as individual and not as one string, i.e. {'APPLE': 2} --> ['A', 'P', 'P', 'L', 'E', 'A', 'P', 'P', 'L', 'E'] and not ['APPLE', 'APPLE'] Here is my code:
def flatten_dict(d):
flattened_dict = []
for key in d:
flattened_dict += flatten_lists(key)*d[key]
return flattened_dict
Thank you for all help