-
Notifications
You must be signed in to change notification settings - Fork 262
Problem solution #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Problem solution #30
Changes from 1 commit
0f1e138
1c8d7d0
88169bb
190192d
85ef5fb
c27c417
dd92056
c63c919
b3ba249
867a711
991276a
7ff8a37
1a2b535
d7696ae
1a9d3bc
2c3c060
0563d48
f4da86c
9b7131c
0b79ba6
7598ae9
fb5366d
191c915
3cc58b3
3aa9ea8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,9 +86,43 @@ def is_user_with_max_messages(messages): | |
|
|
||
| # 2. Вывести айди пользователя, на сообщения которого больше всего отвечали. | ||
| def is_user_with_max_reply_messages(messages): | ||
| pass | ||
|
|
||
| # 1. Формируем список id сообщений на которые отвечали -> уникальные | ||
| messages_id_that_were_replied = [] | ||
| for message in messages: | ||
| if message["reply_for"] != [] and message["reply_for"] is not None: | ||
| messages_id_that_were_replied.append(message["reply_for"]) | ||
|
|
||
| unique_messages_id_that_were_replied = set(messages_id_that_were_replied) | ||
|
|
||
| # 2. Формируем список словарей: id сообщения, кол-во сообщений-ответов на это сообщение | ||
| messages_id_that_were_replied_with_sum_of_answers = [] | ||
| for message_id in unique_messages_id_that_were_replied: | ||
| messages_id_that_were_replied_with_sum_of_answers.append({ | ||
| "message_id": message_id, | ||
| "number_of_answers": messages_id_that_were_replied.count(message_id), | ||
| }) | ||
| print(messages_id_that_were_replied_with_sum_of_answers) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Эти принты хороши для дебага, но из финальной версии их надо удалять. |
||
|
|
||
| # 3. Выводим id сообщения с максимальным количеством ответов на него | ||
| message_id_with_max_sum_of_answers = max(messages_id_that_were_replied_with_sum_of_answers, key=lambda x: x[ | ||
| "number_of_answers"]) | ||
| print(f'айди сообщения sum = {message_id_with_max_sum_of_answers}') | ||
|
|
||
| # 4. Кладем в пременную id сообщения с максимальным количеством ответов на него | ||
| message_id_with_max_sum_of_answers_var = message_id_with_max_sum_of_answers['message_id'] | ||
| print(f'айди сообщения = {message_id_with_max_sum_of_answers_var}') | ||
|
|
||
| # 5. Формируем словарь из id сообщений и id пользователей-отправителей этих сообщений | ||
| messages_id_and_users_id_sent_by = {} | ||
| for message in messages: | ||
| messages_id_and_users_id_sent_by[message["id"]] = message["sent_by"] | ||
| print(f'Словарь = {messages_id_and_users_id_sent_by}') | ||
|
|
||
| # 6. Выводим id пользователя на сообщения которого больше всего отвечали | ||
|
|
||
| return messages_id_and_users_id_sent_by[message_id_with_max_sum_of_answers_var] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут получается, что ты выводишь айди пользователя, который написал сообщение, на которое ответило больше всего пользователей. Это неправильно. Нам нужно найти пользователя, сообщения которого больше всего просматривали в сумме. То есть он мог написать оч много сообщений с небольшим количеством ответов. Это не обязательно автор самого отвечаемого сообщения. |
||
|
|
||
| if __name__ == "__main__": | ||
| messages = generate_chat_history() | ||
| print(is_user_with_max_messages(messages)) | ||
| print(is_user_with_max_reply_messages(messages)) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут было бы логично сделать не список из словарей, а просто словарь. Айди сообщения: количество ответов.