Write a function that takes a list and an integer, t and i, and modifies t by repeating it
i times.
>>> t = [1, 'ani']
>>> repeat_list(t, 3)
>>> t
[1, 'ani', 1, 'ani', 1, 'ani']
Write a function that takes a positive integer, i and returns a dictionary that maps
integers from 1 to i. Each integer is going to map itself. Example:
>>> create_dict(3)
{1: 1, 2: 2, 3: 3}
>>> create_dict(1)
{1: 1}
Write a function that takes a list of strings and returns sum of length of each string.
Example:
>>> get_length(["You", "talking", "to", "me", "?"])
15
Write a function, get_most_active_user, that takes the borrowed dictionary
and returns the user who borrowed the most books.
If there are multiple users with the same maximum, return any one of them. Example:
>>> borrowed = {"Alice": ["1984", "The Hobbit"], "Bob": ["Python"]}
>>> get_most_active_user(borrowed)
'Alice'
Write a function that takes a list of strings and returns a dictionary mapping strings
to their length. Example:
>>> get_length(['yes', 'no' ,'a', 'b'])
{'yes': 3, 'no': 2 ,'a': 1, 'b': 1}
Write a function that takes a dictionary and returns sum of all integers (whether they are
keys or values).
Example:
>>> get_sum({1: 'a', 2: 6, 12: 'po', 'jo': 4})
25
def dosmth(s, chars):
res = ""
for letter in s:
if letter in chars:
res = res + letter
return len(res)
Given the above script, what are the results of the following expressions:
| dosmth('python programming', 'pom'): | ||
| dosmth('python programming', 'arr'): |
def update(lst, i, j):
lst[i][j] = lst[i-1][j] + 2
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')