forked from learnpythonru/basic_exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
последняя работающая версия 5го задания #4
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
Open
SashaLesik
wants to merge
1
commit into
main
Choose a base branch
from
new_branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |||||
| # Вася: 1 | ||||||
| # Маша: 2 | ||||||
| # Петя: 2 | ||||||
| from collections import Counter | ||||||
|
|
||||||
|
|
||||||
| students = [ | ||||||
| {'first_name': 'Вася'}, | ||||||
|
|
@@ -12,21 +14,30 @@ | |||||
| {'first_name': 'Маша'}, | ||||||
| {'first_name': 'Петя'}, | ||||||
| ] | ||||||
| # ??? | ||||||
|
|
||||||
| list_names = list() | ||||||
| for dicts in students: | ||||||
| new_name = (dicts['first_name']) | ||||||
| list_names.append(new_name) | ||||||
|
|
||||||
| for li in set(list_names): | ||||||
| list_count = list_names.count(li) | ||||||
| print(f'{li}:{list_count}') | ||||||
|
|
||||||
|
|
||||||
| # Задание 2 | ||||||
| # Дан список учеников, нужно вывести самое часто повторящееся имя | ||||||
| # Пример вывода: | ||||||
| # Самое частое имя среди учеников: Маша | ||||||
| students = [ | ||||||
| students_2 = [ | ||||||
| {'first_name': 'Вася'}, | ||||||
| {'first_name': 'Петя'}, | ||||||
| {'first_name': 'Маша'}, | ||||||
| {'first_name': 'Маша'}, | ||||||
| {'first_name': 'Оля'}, | ||||||
| ] | ||||||
|
|
||||||
|
|
||||||
| list_names = list() | ||||||
| for dicts in students_2: | ||||||
| new_name = dicts['first_name'] | ||||||
|
|
@@ -44,15 +55,6 @@ | |||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| # Задание 3 | ||||||
| # Есть список учеников в нескольких классах, нужно вывести самое частое имя в каждом классе. | ||||||
| # Пример вывода: | ||||||
|
|
@@ -114,7 +116,7 @@ | |||||
| } | ||||||
|
|
||||||
| for lists in school: | ||||||
| count_boys = 0 # Вопрос: можно ли здесь использовать enumerate (Если да, то как?) | ||||||
| count_boys = 0 | ||||||
| count_girls = 0 | ||||||
| for dict in lists["students"]: | ||||||
| name = dict['first_name'] | ||||||
|
|
@@ -127,4 +129,85 @@ | |||||
| print(f''' В классе {lists["class"]} мальчики {count_boys}, | ||||||
| девочки {count_girls} ''') | ||||||
|
|
||||||
|
|
||||||
| # Задание 5 | ||||||
| # По информации о учениках разных классов нужно найти класс, в котором больше всего девочек и больше всего мальчиков | ||||||
| # Пример вывода: | ||||||
| # Больше всего мальчиков в классе 3c | ||||||
| # Больше всего девочек в классе 2a | ||||||
|
|
||||||
| school = [ | ||||||
| {'class': '2a', 'students': [{'first_name': 'Маша'}, {'first_name': 'Оля'}]}, | ||||||
| {'class': '3c', 'students': [{'first_name': 'Олег'}, {'first_name': 'Миша'}]}, | ||||||
| ] | ||||||
| is_male = { | ||||||
| 'Маша': False, | ||||||
| 'Оля': False, | ||||||
| 'Олег': True, | ||||||
| 'Миша': True, | ||||||
| } | ||||||
|
|
||||||
| final_dict ={} | ||||||
| for lists in school: | ||||||
| print(lists) | ||||||
| count_boys = 0 | ||||||
| count_girls = 0 | ||||||
|
|
||||||
|
|
||||||
| for dict in lists["students"]: | ||||||
|
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.
Suggested change
|
||||||
| print(dict) | ||||||
| name = dict['first_name'] | ||||||
| print(name) | ||||||
|
|
||||||
| if is_male[name]: | ||||||
| count_boys += 1 | ||||||
| else: | ||||||
| count_girls += 1 | ||||||
| final_dict[lists["class"]] = (count_boys, count_girls) | ||||||
|
|
||||||
| print(count_girls) | ||||||
| print(count_boys) | ||||||
|
|
||||||
|
|
||||||
| print(final_dict) | ||||||
| items = final_dict.items() | ||||||
| print(items) | ||||||
| class_name_boys, class_data_boys = max(items, key=lambda item: item[1][0]) | ||||||
| class_name_girls, class_data_girls = max(items, key=lambda item: item[1][1]) | ||||||
| print(f'Больше всего мальчиков в классе {class_name_boys}') | ||||||
| print(f'Больше всего девочек в классе {class_name_girls}') | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| #if (count_boys + number) > (count_girls+number): | ||||||
| #print(f"в классе {class_name} больше мальчиков") | ||||||
| #elif (count_boys + number) == (count_girls+number): | ||||||
| #print(f"в классе {class_name} одинаково мальчиков и девочек") | ||||||
| #else: | ||||||
| #print(f"в классе {class_name} больше девочек") | ||||||
|
|
||||||
| #for lists_ in final_list: | ||||||
| # number_1 = lists_1[class_name] | ||||||
| #print(number_1) | ||||||
|
|
||||||
| #print(f'''Больше всего девочек{(max_val_girls)} | ||||||
| #в классе: {class_name}, | ||||||
| #Больше всего мальчиков {max(count_boys)} | ||||||
| #в классе{class_name}''') | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.