Created
April 8, 2016 21:23
-
-
Save blackknight36/68ffb473b8286d97aa0513fc2e04436f to your computer and use it in GitHub Desktop.
count words with $n letters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| f = open("input.txt", "ro") | |
| words = f.readline().split(" ") | |
| f.close() | |
| limit = len(max(words, key=len)) + 1 | |
| for i in range(1, limit): | |
| count = 0 | |
| for word in words: | |
| if len(word) == i: | |
| count += 1 | |
| print "%s words with %d letter(s)" %(count, i) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment