##### Counting the number of letters in a string alphabetically
 Counting the number of letters in a string alphabetically TreasureDragon Programmer named Tim Posts: 7 Threads: 3 Joined: Feb 2019 Reputation: Mar-06-2019, 09:24 PM (This post was last modified: Mar-06-2019, 09:24 PM by TreasureDragon.) This is what I have so far and it is able to print out how many times a letter was printed but in order which it shows up in the string. I want it to first categorize by the number of times it popped up like the example output: (Also mine counts spaces, punctuations, etc. too but I don't want that) ```Sentence Statistics : e appeared 3 times . a appeared 2 times . g appeared 2 times . l appeared 2 times . o appeared 2 times . c appeared 1 times . d appeared 1 times . i appeared 1 times . m appeared 1 times . n appeared 1 times . t appeared 1 times . w appeared 1 times .```Yes with the space between >1 and 1. This is what I have: ```string = input("Enter a Sentence: ") print(f"\nSentence Statistics:") one = 0 from collections import Counter count = Counter(string) for i in string: if count[i] == 1 and one == 0: print(f"\n{i} appeared {count[i]} times.") one += 1 elif count[i] == 1 and one >= 1: print(f"{i} appeared {count[i]} times.") if count[i] > 1: print(f"{i} appeared {count[i]} times.")``` Reply Posts: 1,782 Threads: 33 Joined: Sep 2016 Reputation: Mar-06-2019, 10:01 PM ```from collections import Counter import string test_string = 'Sentence Statistics' counter = Counter(test_string) for item, count in counter.most_common(): if item in string.ascii_letters: print(f'{item} appeared {count} times')`````````Output:t appeared 4 times e appeared 3 times S appeared 2 times n appeared 2 times c appeared 2 times i appeared 2 times s appeared 2 times a appeared 1 times`````` Reply TreasureDragon Programmer named Tim Posts: 7 Threads: 3 Joined: Feb 2019 Reputation: Mar-07-2019, 01:03 AM (This post was last modified: Mar-07-2019, 01:03 AM by TreasureDragon.) (Mar-06-2019, 10:01 PM)Yoriz Wrote: ```from collections import Counter import string test_string = 'Sentence Statistics' counter = Counter(test_string) for item, count in counter.most_common(): if item in string.ascii_letters: print(f'{item} appeared {count} times')`````````Output:t appeared 4 times e appeared 3 times S appeared 2 times n appeared 2 times c appeared 2 times i appeared 2 times s appeared 2 times a appeared 1 times`````` Nice. It's working like a charm. Just how do I alphabetize within the same amount of appearances? Also how do I make it case-insenstitive? Here's the updated code: ```from collections import Counter import string istring = input("Enter your sentence: ") counter = Counter(istring) one = 0 print(f"\nSentence Statistics:") for item, count in counter.most_common(): if item in string.ascii_letters: if count != 1: print(f'{item} appeared {count} times.') if count == 1 and one == 0: one += 1 print(f'\n{item} appeared {count} times.') elif count == 1 and one != 0: print(f'{item} appeared {count} times.')``` Reply

 Possibly Related Threads… Thread Author Replies Views Last Post TypeError: int() argument must be a string, a bytes-like object or a number, not 'Non Anldra12 2 802 May-02-2021, 03:45 PM Last Post: Anldra12 cursor.execute: How to insert dynamic number in a string? stoeberhai 2 648 Mar-18-2021, 12:55 PM Last Post: stoeberhai Counting number of words and organize for the bigger frequencies to the small ones. valeriorsneto 1 334 Feb-05-2021, 03:49 PM Last Post: perfringo Regular expression: cannot find 1st number in a string Pavel_47 2 561 Jan-15-2021, 04:39 PM Last Post: bowlofred counting vowels in a string project_science 3 623 Dec-30-2020, 06:44 PM Last Post: buran Replacing a words' letters in a string cananb 2 560 Dec-01-2020, 06:33 PM Last Post: perfringo Counting Number of Element in a smart way quest 2 480 Nov-09-2020, 10:24 PM Last Post: quest Please support regex for version number (digits and dots) from a string Tecuma 4 819 Aug-17-2020, 09:59 AM Last Post: Tecuma Counting vowels in a string (PyBite #106) Drone4four 4 768 Jul-07-2020, 05:29 AM Last Post: theknowshares get method not counting number of strings in dictionary LearningTocode 2 616 Jun-13-2020, 11:17 PM Last Post: LearningTocode

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020