Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1)
- from collections import defaultdict
- num_records = int(input("Введите число строк: "))
- votes = [input("Введите имена в алф. порядке и число голосов: ").split() for _ in range(num_records)]
- results = defaultdict(int)
- for candidate, count in votes:
- results[candidate] += int(count)
- for candidate in sorted(results):
- print(f"{candidate} {results[candidate]}")
- 2)
- strings = int(input("Ввести кол-во строк: "))
- text = " ".join(input("Ввести строки(у): ") for i in range(strings)).lower()
- word_counts = {}
- for word in text.split():
- if word in word_counts:
- word_counts[word] += 1
- else:
- word_counts[word] = 1
- most_frequent_word = min(word_counts, key = lambda word: (-word_counts[word], word))
- print(most_frequent_word)
- 3)
- n = int(input("Ввести число файлов: "))
- file_permissions = {}
- for i in range(n):
- file, *permissions = input("Ввести файл и операцию через пробел: ").split()
- file_permissions[file] = set(permissions)
- m = int(input("Ввести кол-во запросов: "))
- for i in range(m):
- operation, file = input("Ввести операцию и файл через пробел: ").split()
- if operation in file_permissions.get(file, set()):
- print("OK")
- else:
- print("Access denied")
- sort_words()
- 4)
- def sort_words():
- num_lines = int(input("Ввести кол-во строк: "))
- text = []
- for _ in range(num_lines):
- text.extend(input("Ввести строки: ").lower().split())
- word_counts = {}
- for word in text:
- word_counts[word] = word_counts.get(word, 0) + 1
- sorted_words = sorted(word_counts.items(), key=lambda item: (-item[1], item[0]))
- for word, _ in sorted_words:
- print(word)
- sort_words()
- 5)
- def find_cities():
- num_countries = int(input("Ввести кол-во стран: "))
- country_cities = {}
- for _ in range(num_countries):
- country, *cities = input("Ввести в ключ: города, в значение: страну ").split()
- for city in cities:
- country_cities[city] = country
- num_queries = int(input("Ввести кол-во запросов: "))
- for _ in range(num_queries):
- city = input("Ввести город: ")
- print(country_cities.get(city, "Страны нет в перечне"))
- find_cities()
- 6)
- def create_latin_english_dict():
- num_english_words = int(input("Ввести кол-во слов в словаре: "))
- english_to_latin = {}
- for _ in range(num_english_words):
- english_word, latin_translations = input("Ввести слова из словаря: ").split(" - ")
- latin_translations = latin_translations.split(", ")
- for latin_word in latin_translations:
- english_to_latin.setdefault(latin_word, []).append(english_word)
- latin_to_english = {}
- for latin_word, english_words in english_to_latin.items():
- latin_to_english[latin_word] = sorted(set(english_words))
- for latin_word in sorted(latin_to_english.keys()):
- english_translations = ", ".join(latin_to_english[latin_word])
- print(f"{latin_word} - {english_translations}")
- create_latin_english_dict()
- 7)
- ---------------
- 8)
- ---------------
- 9)
- def determine_heights():
- num_people = int(input("Ввести число элементов в генеалогическом древе: "))
- parent_child = {}
- for _ in range(num_people - 1):
- child, parent = input("Ввести имя ребёнка и имя родителя через пробел: ").split()
- parent_child[child] = parent
- heights = {}
- def calculate_height(person):
- if person not in heights:
- if person not in parent_child:
- heights[person] = 0
- else:
- heights[person] = calculate_height(parent_child[person]) + 1
- return heights[person]
- for person in sorted(parent_child.keys()):
- print(person, calculate_height(person))
- determine_heights()
- 10)
- ------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement