Created
September 13, 2025 10:57
-
-
Save delululala/eef2752b97900fba3d185c4fc6eafbae to your computer and use it in GitHub Desktop.
Python4E Exercice
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
| name = input("Enter file:") | |
| if len(name) < 1: | |
| name = "mbox-short.txt" | |
| handle = open(name) | |
| counts = dict() | |
| for line in handle: | |
| line = line.strip() | |
| if line.startswith('From '): | |
| word = line.split() | |
| time = word[5] | |
| hour = time.split(':')[0] | |
| counts[hour] = counts.get(hour,0) + 1 | |
| for k,v in sorted(counts.items()): | |
| print(k,v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment