You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Deze repo is gearchiveerd. U kunt bestanden bekijken en het klonen, maar niet pushen of problemen/pull-requests openen.

06-top-words.py 624 B

6 jaren geleden
6 jaren geleden
6 jaren geleden
6 jaren geleden
6 jaren geleden
6 jaren geleden
6 jaren geleden
6 jaren geleden
123456789101112131415161718192021222324252627282930313233343536
  1. import sys
  2. def get_value(pair):
  3. key, value = pair
  4. return value
  5. def get_word(chunk):
  6. if all(x.isalpha() for x in chunk):
  7. if len(chunk) < 4:
  8. return None
  9. return chunk.lower()
  10. else:
  11. return None
  12. def main():
  13. filename = sys.argv[1]
  14. file = open(filename, "r")
  15. scores = {}
  16. for line in file.readlines():
  17. for chunk in line.split():
  18. word = get_word(chunk)
  19. if word:
  20. if not word in scores:
  21. scores[word] = 0
  22. else:
  23. scores[word] += 1
  24. file.close()
  25. main()