I am trying to create a new dictionary from an english language dictionary that i have using PyEnchant.For example : the english word--> 'new' to become--> 'new':1e1n1w (i am counting the letters alphabetically) My problem is that i do not know how to access the objects of the english language dictionary so i can make a repetition structure and create the ne dictionary or change this one.(I have two files that make the dictionary , one FFT and one txt.)
Start from a word and convert it to letter count / letter format, sorted alphabetically:
from collections import Counter
s = "new"
c = Counter(s)
print("".join(["{}{}".format(v,k) for k,v in sorted(c.items())]))
Counter
dictionary made for that purposestr.join
results in: 1e1n1w
One-liner to create the list from input list (here: 2 items) using listcomps:
newlist = ["".join(["{}{}".format(v,k) for k,v in sorted(Counter(word).items())]) for word in ['new','hello']]
results in:
['1e1n1w', '1e1h2l1o']