Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Dictionaries - Lab Python Fundamentals 100/100
- # https://judge.softuni.org/Contests/Practice/Index/1736#6
- ////////////////////////////////////////////////////////////////////
- # 01. Bakery
- bakery = input().split()
- bakery_dict = {}
- for i in range(0, len(bakery), 2):
- key = bakery[i]
- value = int(bakery[i + 1])
- bakery_dict[key] = value
- print(bakery_dict)
- ////////////////////////////////////////////////////////////////////
- # 02. Stock
- data = input().split()
- searched = input().split()
- products = {}
- for i in range(0, len(data), 2):
- key = data[i]
- value = data[i + 1]
- products[key] = value
- for word in searched:
- if word in products:
- print(f"We have {products[word]} of {word} left")
- else:
- print(f"Sorry, we don't have {word}")
- ////////////////////////////////////////////////////////////////////
- # 03. Statistics
- data = input()
- products = {}
- while not data == 'statistics':
- data = data.split(': ')
- key = data[0]
- value = int(data[1])
- if key not in products:
- products[key] = value
- else:
- products[key] += value
- data = input()
- print("Products in stock:")
- for key, value in products.items():
- print(f"- {key}: {value}")
- print(f"Total Products: {len(products)}")
- print(f"Total Quantity: {sum(products.values())}")
- ////////////////////////////////////////////////////////////////////
- # 04. Students
- data = input()
- courses = {}
- while ":" in data:
- student_name, id, course_name = data.split(":")
- if course_name not in courses:
- courses[course_name] = {}
- courses[course_name][id] = student_name
- data = input()
- searched_course = data
- searched_course_name_as_list = searched_course.split("_")
- searched_course = ' '.join(searched_course_name_as_list)
- for course_name in courses:
- if course_name == searched_course:
- for id, name in courses[course_name].items():
- print(f"{name} - {id}")
- ////////////////////////////////////////////////////////////////////
- # 05. ASCII Values
- data = input().split(", ")
- letter_dict = {}
- for i in range(0,len(data)):
- key = data[i]
- value = ord(data[i])
- letter_dict[key] = value
- print(letter_dict)
- ////////////////////////////////////////////////////////////////////
- # 06. Odd Occurrences
- words = input().split(" ")
- my_dict = {}
- for word in words:
- word_lower = word.lower()
- if word_lower not in my_dict:
- my_dict[word_lower] = 0
- my_dict[word_lower] += 1
- for (key, value) in my_dict.items():
- if value % 2 != 0:
- print(key, end=' ')
- ////////////////////////////////////////////////////////////////////
- # 07. Word Synonyms
- n = int(input())
- synonym_dict = {}
- for i in range(n):
- word = input()
- synonym = input()
- if word not in synonym_dict:
- synonym_dict[word] = []
- synonym_dict[word].append(synonym)
- for el in synonym_dict:
- print(f'{el} - {", ".join(synonym_dict[el])}')
- ////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement