Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 03. Dictionary - Final exam 100/100
- ====================================================================================================================
- # var 1
- data = input().split(' | ')
- my_dict = {}
- for current_word in data:
- current_word = current_word.split(': ')
- word = current_word[0]
- definition = current_word[1]
- if word not in my_dict.keys():
- my_dict[word] = []
- my_dict[word].append(definition)
- elif word in my_dict.keys() and definition not in my_dict.values():
- my_dict[word].append(definition)
- teacher_words = input().split(' | ')
- command = input()
- if command == 'Test':
- for searched_key in teacher_words:
- if searched_key in my_dict.keys():
- print(f'{searched_key}:')
- for key_word in my_dict[searched_key]:
- print(f' -{key_word}')
- elif command == 'Hand Over':
- for key_word in my_dict:
- print(key_word, end=' ')
- ====================================================================================================================
- # var 2 functions
- def final_print_func(some_words, some_command, some_dict):
- if some_command == 'Test':
- for searched_key in some_words:
- if searched_key in some_dict.keys():
- print(f'{searched_key}:')
- for key_word in some_dict[searched_key]:
- print(f' -{key_word}')
- elif command == 'Hand Over':
- for key_word in some_dict:
- print(key_word, end=' ')
- def create_initial_dict_func():
- data = input().split(' | ')
- initial_dict = {}
- for current_word in data:
- current_word = current_word.split(': ')
- word = current_word[0]
- definition = current_word[1]
- if word not in initial_dict.keys():
- initial_dict[word] = []
- initial_dict[word].append(definition)
- elif word in initial_dict.keys() and definition not in initial_dict.values():
- initial_dict[word].append(definition)
- return initial_dict
- my_dict = create_initial_dict_func()
- teacher_words = input().split(' | ')
- command = input()
- final_print_func(teacher_words, command, my_dict)
- ====================================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement