Quote:
Originally Posted by cooolsson
I have this code here
- import string
-
def count_and_sort():
-
filer = {}
-
f = open("loggfil.txt","r")
-
f2 = open("lab5.out","w")
-
person = "lisa.sm.luth.se"
-
while True:
-
rad = f.readline()
-
split = string.split(rad)
-
if rad == "":
-
f.close()
-
break
-
elif person in rad:
-
split2 = split[6]
-
filer[split2] = filer.get(split2,0) + 1
-
keys = filer.keys()
-
keys.sort()
-
for lines in keys:
-
f2.write(lines+"\n")
-
f.close()
this code prints out this from a log file
//csee/csn/include/div.cfg
/csee/csn//include/address.html
/csee/csn//include/footmenu.html
/csee/csn//include/links.html
/csee/csn/presentation.html
/csee/csn/research.html
I want it to display on the side of the filename how many times you downloaded it. I put everything in a dictionary but i can only get the keys. How do i get the values. Thanks in advance
Please use code tags around your code!
To write the file name and quantity:
- f2.write("\n".join(["%s %s" % (key, filer[key]) for key in keys]))