Write a function that takes two lists of numbers (with the same length), t1 and t2,
and returns a new list which item of index i is sum of t1[i] and t2[i].
Example:
>>> add_lists([1, 2, 3], [1, 3, 1])
[2, 5, 4]
Write a function that takes a list of integers, t, and returns a new list which contains only
even integers of t.
>>> a = [4, 3, 1, 2, 5, 2]
>>> d = get_evens(a)
>>> d
[4, 2, 2]
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": 10, "review": "Masterpiece"}
}
}
Write a function, {get_most_rated_movies(users: dict)}, that returns a list of movies
sorted by how many users have rated them (most to least). Example:
>>> get_most_rated_movies(users)
[('Inception', 2), ('Titanic', 1), ('Interstellar', 1)]
Write a function that takes a list and two different positive integers, lst, i and j,
it deletes lst elements with index i and j and returns None.
Example:
>>> t = ['po', 'ani', 'jo', 'pra']
>>> delete_i(t, 1, 3)
>>> t
['po', 'jo']
Write a function that takes a dictionary whose values are strings, and returns sum of length
all of values.
Example:
>>> get_string({1: "ani", 2: "o", -1: "pse"})
7
Write a function that takes a list and two integers, t, i and j changes t elements from
index i to index j (including i not including j) with None
>>> a = [4, 3, 1, 2, 'ani', 'po']
>>> change_list(a, 1, 4)
>>> a
[4, None, None, None, 'ani', 'po']
def dosmth(s, char):
c = 0
for i in range(len(s)):
if s[i] == char:
c = c + i
return c
Given the above script, what are the results of the following expressions:
| dosmth('baba', 'b'): | ||
| dosmth('nana', 'a'): |
def update(lst, i, j):
lst[i] = lst[j][i] + 1
nums = [[0, 0], [1, 1], [2, 2]]
update(nums, 1, 1)
print(nums)
update(nums, -1, 0)
print(nums)
Given the above script, write the printed values in the order that they appear.
| 1: | ||
| 2: |
Complete execution flow of the following program
def add_number(d, n): for key in d: d[key] = d[key] + n nums = {'a': 1, 2: 4} nums = add_number(nums, -4)
Complete execution flow of the following program
def histogram(s): d = {} for c in s: d[c] = d.get(c, 0) + 1 return d h = histogram('oob')