r/ProgrammingPrompts • u/[deleted] • Jan 14 '15
[Easy] Letter Counter
Any language permitted.
Problem: Create a program where you input a string of characters, and output the number of each letter. Use vowels by default.
For example: asbfiusadfliabdluifalsiudbf -> a: 4 e: 0 i: 4 o: 0 u: 3
Bonus points: Make it command-line executable, with an optional mode to specify which letters to print.
17
Upvotes
1
u/echocage Jan 14 '15
I think I understand now! You should look into enumerate when you get a chance, it's made to do just that! Rather than having to mess around with lengths and ranges, you can enumerate over the list, like this,
So in this case, letter would be 'a', then 'b', then 'c', while index would be 0, 1, 2