Skip to content

Instantly share code, notes, and snippets.

@blackknight36
Created April 8, 2016 21:23
Show Gist options
  • Select an option

  • Save blackknight36/68ffb473b8286d97aa0513fc2e04436f to your computer and use it in GitHub Desktop.

Select an option

Save blackknight36/68ffb473b8286d97aa0513fc2e04436f to your computer and use it in GitHub Desktop.
count words with $n letters
#!/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