forked from gil9red/SimplePyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalysisOfChatLog.py
More file actions
25 lines (20 loc) · 947 Bytes
/
Copy pathAnalysisOfChatLog.py
File metadata and controls
25 lines (20 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# coding=utf-8
__author__ = 'ipetrash'
# Есть лог-файл какого-то чата. Посчитать «разговорчивость» пользователей в нем в виде ник — количество фраз.
# Посчитать среднее число букв на участника чата.
if __name__ == '__main__':
#file_name = raw_input("Chat log file: ")
file_name = "C:\Users\ipetrash\Desktop\chat log.txt"
user_count = {}
for line in file(file_name):
line = line.decode("windows-1251").replace("\n", "")
user, count = line.split(":")[0], len(line.split(":")[1].split(' ')) - 1
if user in user_count:
user_count[user] += count
else:
user_count[user] = count
sum = 0.0
for user, count in user_count.items():
sum += count
print(user + " = %d" % count)
print("Average = %s" % (sum / len(user_count)) )