Write a function that takes a list and returns a new list which is reverse of the input list.
>>> a = [4, 3, 1, 2]
>>> d = reverse_list(a)
[2, 1, 3, 4]
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 strings and a character, t and char
and returns count of strings which start with char (case insensitive).
>>> startswith_count(['A', 'a', 'bs', 'Ne', 'Aron'], 'a')
3
>>> count = startswith_count(['A', 'Barber', 'Bask', 'bs', 'Ne', 'BS', 'BS'], 'B')
>>> count
5
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 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 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 ani(word, char):
index = 0
t = 0
while index < len(word):
if word[index] == char:
t = t + index
index = index + 1
return t
def add(word, ch1, ch2):
return ani(word, ch1) + ani(word, ch2)
Given the above script, what are the results of the following expressions:
| add('kungfu panda', 'k', 'u'): | ||
| add('kungfu panda', 'f', 'g'): |
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 histogram(s): d = {} for c in s: d[c] = d.get(c, 0) + 1 return d h = histogram('oob')
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)