Skip to content

Commit 7598ae9

Browse files
author
Alexey Chernykh
committed
Решение 1 задачи в for_dict_challenges_bonus.py
1 parent 0b79ba6 commit 7598ae9

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

for_dict_challenges_bonus.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
Пожалуйста, приступайте к этой задаче после того, как вы сделали и получили ревью ко всем остальным задачам
2+
Пожалуйста,
3+
приступайте к этой задаче после того, как вы сделали и получили ревью ко всем остальным задачам
34
в этом репозитории. Она значительно сложнее.
45
56
@@ -55,5 +56,29 @@ def generate_chat_history():
5556
return messages
5657

5758

59+
# 1. Вывести айди пользователя, который написал больше всех сообщений.
60+
def is_user_with_max_messages(messages):
61+
id_list = []
62+
for message in messages:
63+
id_list.append(message["sent_by"])
64+
uniq_id_list = list(set(id_list))
65+
66+
count_of_message_id = {}
67+
for id_uniq in uniq_id_list:
68+
counter = 0
69+
for id in id_list:
70+
if id_uniq == id:
71+
counter += 1
72+
count_of_message_id[id_uniq] = counter
73+
74+
count_of_message_id_sorted = dict(sorted(count_of_message_id.items(), key=lambda item: item[1], reverse=True))
75+
count_of_message_id_sorted_list = [id for id in count_of_message_id_sorted]
76+
return count_of_message_id_sorted_list[0]
77+
78+
5879
if __name__ == "__main__":
59-
print(generate_chat_history())
80+
messages = generate_chat_history()
81+
print(is_user_with_max_messages(messages))
82+
83+
84+

0 commit comments

Comments
 (0)