Hello

I have generated a list of words & their occurrences.
Now, how to I filter them based to the starting alphabet. I.e. all words starting with 'a' should be filtered from thos list & put into 1 list along with their occurrences, similarly b,c & d.

This is the list I've generated.It shows the words & the number of occurrences of the words.

[('a', 4574), ('abandon', 3), ('abandoned', 8), ('abandoning', 1), ('abide', 1), ('ability', 2), ('abjectly', 1), ('abjure', 1), ('able', 45), ('abnormal', 4), ('abnormality', 1), ('abolition', 1), ('about', 487), ('above', 27), ('babbled', 1), ('baby', 1), ('back', 131), ('backed', 1), ('backing', 1), ('backs', 1), ('backwards', 2), ('bad', 25), ('bade', 2), ('badly', 10), ('bags', 2), ('baked', 1), ('baking', 1), ('balance', 1), ('balancing', 1), ('balcony', 1), ('bald', 1), ('ball', 3), ('balloon', 3), ('balls', 1), ('bandage', 1), ('banging', 2), ('bank', 9), ('bankrupt', 1), ('banks', 4), ('banquets', 1), ('bantering', 1), ('bar', 3), ('bare', 9), ('bared', 1), ('barefoot', 1), ('bareheaded', 1), ('barely', 1), ('bargain', 1), ('bargained', 1), ('baring', 1), ('barking', 1), ('barracks', 1), ('barred', 1), ('barrel', 1), ('barricade', 1), ('barrier', 1), ('barriers', 2), ('barter', 2), ('base', 6), ('based', 2),  ('cease', 4), ('ceased', 13), ('ceasing', 1), ('ceiling', 1), ('ceilings', 1), ('celebrate', 1), ('cellar', 1), ('censorship', 1), ('censure', 1), ('centered', 1), ('central', 1), ('centre', 1), ('centres', 1), ('century', 2), ('ceremoniously', 1), ('ceremony', 3), ('certain', 66), ('certainly', 63), ('certainty', 2), ('certificate', 7), ('cesspool', 1), ('chain', 3), ('chair', 26), ('chairs', 5), ('chalk', 1), ('challenge', 1), ('challenged', 1), ('challenging', 2), ('chamois', 2), ('champagne', 6), ('champion', 1), ('chance', 16), ('chanced', 5), ('change', 21), ('changed', 19), ('changes', 1), ('changing', 3), ('chantant', 1), ('chanted', 1), ('chapter', 40), ('character', 15), ('characteristic', 4), ('characteristics', 2), ('charge', 9), ('charged', 1), ('charges', 1), ('charitable', 2), ('charities', 1), ('charm', 1), ('charmed', 1), ('charming', 4), ('charwoman', 1), ('chase', 1),  ('defiled', 1), ('definite', 9), ('definitely', 1), ('deformed', 1), ('degradation', 1), ('degrade', 1), ('degraded', 1), ('degrading', 2), ('degree', 2), ('degrees', 7), ('deigned', 1), ('deigning', 1), ('dejected', 3), ('dejectedly', 2), ('delay', 2), ('delayed', 1), ('deletions', 1), ('deliberate', 2), ('deliberately', 3), ('deliberating', 1), ('deliberation', 1), ('delicacy', 2), ('delicate', 5), ('delicately', 2), ('delight', 1), ('delighted', 10), ('delightful', 3), ('delirious', 7), ('delirium', 9), ('deliverance', 2), ('delivered', 2), ('delusions', 1), ('demand', 3), ('demanded', 1), ('demands', 3), ('demonstrations', 1), ('demoralisation', 1), ('den', 2), ('denied', 1), ('dens', 1), ('dense', 1), ('denser', 1), ('deny', 10), ('denying', 2), ('departed', 1), ('departing', 1), ('department', 3), ('departure', 2), ('depend', 4), ('depended', 4), ('dependent', 4), ('depending', 1), ('depends', 8), ('depose', 1), ('depositing', 1), ('deposition', 1), ('depraved', 2), ('depravity', 2), ('depressed', 2), ('depression', 1), ('deprived', 1), ('depriving', 1), ('depth', 1), ('depths', 2)]

Thank you!:)

if I could do something like sort all values

Try a normal list sort and then print it to see if it is in the order you want. You can then go through the list item by item, and if the first letter of this word is different from the first letter of the previous word, start a new list, although I would use a dictionary of lists.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.