I'm new to programming and I'm doing a text mining task. I have a dictionary with the keys as tokens and values as the occurrence of the token in the database.
dic={'a':48,'b':32,'c':26}
and also I have a list of tokens, and I'm trying to create a new list with the occurrence of each token. if a token is not found in the dictionary, append 0.
my_list=['a','b','d','c','a']
ideal_output=[48,32,0,26,48]
my original code is like this:
for word in my_list:
for k,v in dic.items():
if word==k:
ideal_output.append(v)
else:
ideal_output.append('0')
but it would yield more integers than I expected, I don't know what's wrong with it. I'd appreciate your help!
current output looks like this
['0', 48, '0', '0', '0', 32, '0', '0', '0', 26, '0', '0', '0', 48, '0']