Skip to content

Instantly share code, notes, and snippets.

@ltc-hotspot
Last active December 30, 2015 16:21
Show Gist options
  • Save ltc-hotspot/60e72b5a3bf73a4c783f to your computer and use it in GitHub Desktop.
Save ltc-hotspot/60e72b5a3bf73a4c783f to your computer and use it in GitHub Desktop.
Meta Data
handle = """From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008
From louis@media.berkeley.edu Fri Jan 4 18:10:48 2008
""".split("\n") # snippet file data: Source-Metadata.txt
count = dict()
fname = raw_input("Enter file name: ")# insert # to add snippet file data
handle = open (fname, 'r')# insert # to add snippet file data
for line in handle:
if line.startswith("From "):
time = line.split() # splitting the lines ->
# print time: ['From', 'stephen.marquard@uct.ac.za', 'Sat', 'Jan', '5', '09:14:16', '2008']
for hours in time: #getting the index pos of time ->
hours = line.split(":")[2] # splitting on ":" ->
line = line.rstrip()
count[hours] = count.get(hours, 0) + 1 # getting the index pos of hours.
lst = [(val,key) for key,val in count.items()] # find the most common words
lst.sort(reverse=True)
for key, val in lst[:12] :
print key, val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment