users = {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"}
},
"Bob": {
"Inception": {"rating": 8, "review": "Loved the visuals"},
"Interstellar": {"rating": 8, "review": "Masterpiece"},
"The Shawshank Redemption": {"rating": 10, "review": "Masterpiece"}
}
}
Write a function, get_most_active_user(users: dict), that returns the name of the user
who has rated the most movies. Example:
>>> get_most_active_user(users)
'Bob'
Write a function that takes a dictionary and two other arguments, d, k and v,
and adds a new item to d with key k and value v. Example:
>>> d = {"tree": "fruit"}
>>> add_value(d, "cow", "milk")
>>> d
{"tree": "fruit", "cow": "milk"}
Write a function that takes no arguments and returns a dictionary with two items, where keys are integers and values are dictionaries.
Write a function, filter_allowed_words(words, allowed),
which returns a list of words that use only the allowed letters. Example:
>>> filter_allowed_words(['apple', 'banana', 'fig', 'grape'], 'aeplgr')
['apple', 'grape']
Write a function that takes a dictionary and prints all of its items (key-value pair),
one per line, in the following format:
value1 key1
value2 key2
...
Example:
>>> print_dict({'one': 1, 'two': 2}
1 'one'
2 'two'
Define a function that takes one list, an integer and a value, t, i and v, and changes the element of t with index i to v.
def sub_list(lst, i, offset):
return lst[i-offset:i]
def element(lst, i, offset):
return lst[i-offset]
t = [1, 2, 3, 4, 5, 6]
t1 = sub_list(t, 4, 1)
t2 = element(t, 4, 1)
What is the value of t1 and t2 at the end of execution of the above script?
| t1: | ||
| t2: |
def dosmth(d, a):
return d.pop(a, None)
questions = {'ku': 'qaty', 'pse': 'sdi', 'jo be': 2}
a = dosmth(questions, 'ku')
b = dosmth(questions, 'ani')
What is the value of the following variables at the end of the execution of the above script?
| a: | ||
| b: | ||
| questions: |
Complete execution flow of the following program
d = {12: 'ab', 23: 'bc'} b = d[12][1] + d[23][0] print(b)
Complete execution flow of the following program
>>>