Advertisement
GeorgiLukanov87

All Dictionaries - Lab Python Fundamentals 100/100

Jul 6th, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.07 KB | None | 0 0
  1. # Dictionaries - Lab Python Fundamentals 100/100
  2.  
  3. # https://judge.softuni.org/Contests/Practice/Index/1736#6
  4.  
  5.  
  6. ////////////////////////////////////////////////////////////////////
  7.  
  8. # 01. Bakery
  9.  
  10. bakery = input().split()
  11. bakery_dict = {}
  12.  
  13. for i in range(0, len(bakery), 2):
  14.     key = bakery[i]
  15.     value = int(bakery[i + 1])
  16.     bakery_dict[key] = value
  17.  
  18. print(bakery_dict)
  19.  
  20. ////////////////////////////////////////////////////////////////////
  21.  
  22. # 02. Stock
  23.  
  24. data = input().split()
  25. searched = input().split()
  26.  
  27. products = {}
  28.  
  29. for i in range(0, len(data), 2):
  30.     key = data[i]
  31.     value = data[i + 1]
  32.     products[key] = value
  33.  
  34. for word in searched:
  35.     if word in products:
  36.         print(f"We have {products[word]} of {word} left")
  37.     else:
  38.         print(f"Sorry, we don't have {word}")
  39.  
  40. ////////////////////////////////////////////////////////////////////
  41.  
  42. # 03. Statistics
  43.  
  44. data = input()
  45. products = {}
  46. while not data == 'statistics':
  47.     data = data.split(': ')
  48.     key = data[0]
  49.     value = int(data[1])
  50.     if key not in products:
  51.         products[key] = value
  52.     else:
  53.         products[key] += value
  54.  
  55.     data = input()
  56.  
  57. print("Products in stock:")
  58.  
  59. for key, value in products.items():
  60.     print(f"- {key}: {value}")
  61.  
  62. print(f"Total Products: {len(products)}")
  63. print(f"Total Quantity: {sum(products.values())}")
  64.  
  65. ////////////////////////////////////////////////////////////////////
  66.  
  67. # 04. Students
  68.  
  69. data = input()
  70. courses = {}
  71.  
  72. while ":" in data:
  73.     student_name, id, course_name = data.split(":")
  74.     if course_name not in courses:
  75.         courses[course_name] = {}
  76.     courses[course_name][id] = student_name
  77.     data = input()
  78.  
  79. searched_course = data
  80. searched_course_name_as_list = searched_course.split("_")
  81. searched_course = ' '.join(searched_course_name_as_list)
  82.  
  83. for course_name in courses:
  84.     if course_name == searched_course:
  85.         for id, name in courses[course_name].items():
  86.             print(f"{name} - {id}")
  87.  
  88. ////////////////////////////////////////////////////////////////////
  89.  
  90. # 05. ASCII Values
  91.  
  92. data = input().split(", ")
  93. letter_dict = {}
  94.  
  95. for i in range(0,len(data)):
  96.     key = data[i]
  97.     value = ord(data[i])
  98.     letter_dict[key] = value
  99.  
  100. print(letter_dict)
  101.  
  102. ////////////////////////////////////////////////////////////////////
  103.  
  104. # 06. Odd Occurrences
  105.  
  106. words = input().split(" ")
  107. my_dict = {}
  108.  
  109. for word in words:
  110.     word_lower = word.lower()
  111.     if word_lower not in my_dict:
  112.         my_dict[word_lower] = 0
  113.     my_dict[word_lower] += 1
  114.  
  115. for (key, value) in my_dict.items():
  116.     if value % 2 != 0:
  117.         print(key, end=' ')
  118.  
  119. ////////////////////////////////////////////////////////////////////
  120.  
  121. # 07. Word Synonyms
  122.  
  123. n = int(input())
  124. synonym_dict = {}
  125.  
  126. for i in range(n):
  127.     word = input()
  128.     synonym = input()
  129.  
  130.     if word not in synonym_dict:
  131.         synonym_dict[word] = []
  132.     synonym_dict[word].append(synonym)
  133.  
  134. for el in synonym_dict:
  135.     print(f'{el} - {", ".join(synonym_dict[el])}')
  136.  
  137. ////////////////////////////////////////////////////////////////////
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement