I am trying to 1st divide up four-letter words based upon the last two letters of the word (suffix) and 2nd count up how many words I have for each of these endings.
I have a list containing 3,164 words called filtered and I have sorted them by their suffixes, which doesn't seem much of a help.
(I want to create a dictionary that takes the suffix as a key and the words as a list but I don't know where to begin!) It would be something like:
OUTPUT:
dic = {'ab': ['Ahab', 'Arab', 'Saab, ...]; 'al': ['Aral', 'Baal', ...]}
and so on. Would that be possible?
filtered.sort(key= lambda x : x[-2:])
print(filtered)
['HSBC', 'UCLA', 'FNMA', 'SARS', 'OHSA', 'Ahab', 'Arab', 'Saab', 'blab', 'crab', 'drab', 'flab', 'grab', 'scab', 'slab', 'stab', 'swab', 'Brad', 'Chad', 'Head', 'Mead', 'Thad', 'Vlad', 'bead', 'brad', 'clad', 'dead', 'glad', 'goad', 'grad', 'head', 'iPad', 'lead', 'load', 'mead', 'quad', 'read', 'road', 'scad', 'shad', 'toad', 'Olaf', 'Piaf', 'deaf', 'leaf', 'loaf', 'brag', 'crag', 'drag', 'flag', 'shag', 'slag', 'snag', 'stag', 'swag', 'Leah', 'Noah', 'Ptah', 'Utah', 'blah', 'shah', 'yeah', 'Thai', 'beak', 'flak', 'leak', 'peak', 'soak', 'teak', 'weak', 'Aral', 'Baal', 'Dial', 'Neal', 'Opal', 'Ural', 'anal', 'coal', 'deal', 'dial', 'dual', 'foal', 'goal', 'heal', 'meal', 'opal', 'oral', 'oval', 'peal', 'real', 'seal', 'teal', 'veal', 'vial', 'weal', 'zeal', 'Adam', 'Edam', 'Elam', 'Guam', 'Siam', 'Spam', 'beam', 'clam', 'cram', 'dram', 'exam', 'foam', 'gram', 'imam', 'loam', 'pram', 'ream', 'roam', 'scam', 'seam', 'sham', 'slam', 'swam', 'team', 'tram', 'wham', 'Adan', 'Alan', 'Bean', 'Bran', 'Chan', 'Dean', 'Evan', 'Fran', 'Iran', 'Ivan', 'Jean', 'Joan', 'Juan', 'Khan', 'Klan', 'Kwan', 'Lean', 'Oman', 'Oran', 'Ryan', 'Sean', 'Sian', 'Stan', 'Tran', 'Yuan', 'bean', 'bran', 'clan', 'dean', 'flan', 'khan', 'lean', 'loan', 'mean', 'moan', 'plan', 'roan', 'scan', 'span', 'swan', 'than', 'wean', 'chap', 'clap', 'crap', 'flap', 'heap', 'leap', 'reap', 'slap', 'snap', 'soap', 'swap', 'trap', 'wrap', 'Iraq', 'Adar', 'Alar', 'Iyar', 'Lear', 'Omar', 'Paar', 'Saar', 'Thar', 'afar', 'agar', 'ajar', 'bear', 'boar', 'char', 'czar', 'dear', 'fear', 'gear', 'hear', 'liar', 'near', 'pear', 'rear', 'roar', 'scar', 'sear', 'soar', 'spar', 'star', 'tear', 'tsar', 'tzar', 'wear', 'year', 'Boas', 'Haas', 'Xmas', 'alas', 'baas', 'bias', 'boas', 'bras', 'eras', 'leas', 'peas', 'seas', 'spas', 'teas', 'yeas', 'Fiat', 'beat', 'boat', 'brat', 'chat', 'coat', 'feat', 'fiat', 'flat', 'frat', 'gnat', 'goat', 'heat', 'meat', 'moat', 'neat', 'peat', 'scat', 'seat'...]