I have a list that contains dictionaries with Letters and Frequencies. Basically, I have 53 dictionaries each for every alphabet (lowercase and uppercase) and space.
adict = {'Letter':'a', 'Frequency':0} bdict = {'Letter':'b', 'Frequency':0} cdict = {'Letter':'c', 'Frequency':0} If you input a word, it will scan the word and update the frequency for its corresponding letter.
for ex in range(0, len(temp)): if temp[count] == 'a': adict['Frequency']+=1 elif temp[count] == 'b': bdict['Frequency']+=1 elif temp[count] == 'c': cdict['Frequency']+=1 For example, I enter the word "Hello", The letters H,e,l,l,o is detected and its frequencies updated. Non zero frequencies will be transferred to a new list.
if adict['Frequency'] != 0 : newArr.append(adict) if bdict['Frequency'] != 0 : newArr.append(bdict) if cdict['Frequency'] != 0 : newArr.append(cdict) After this, I had the newArr sorted by Frequency and transferred to a new list called finalArr. Below is a sample list contents for the word "Hello"
{'Letter': 'H', 'Frequency': 1} {'Letter': 'e', 'Frequency': 1} {'Letter': 'o', 'Frequency': 1} {'Letter': 'l', 'Frequency': 2} Now what I want is to transfer only the key values to 2 seperate lists; letterArr and numArr. How do I do this? my desired output is:
letterArr = [H,e,o,l] numArr = [1,1,1,2]
freq_dict = {'a': 0, 'b': 0, ...}. Then it would be easy to transfer frequencies into a list.