Write a function that takes two strings of the same length, s1 and s2,
and returns a dictionary which maps s1[i] with s2[i].
Example:
>>> map_strings('ani', 'pse')
{'a': 'p', 'n': 's', 'i': 'e'}
Write a function that takes a list of integers, t, it returns sum of all integers and deletes all
elements from t.
>>> a = [4, 3, 1, 2, 5, 2]
>>> d = get_sum(a)
>>> d
17
>>> a
[]
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 two dictionaries and counts how many key-value pairs
are exactly the same in both dictionaries.
Only count pairs where the key and the value are the same in both..
Example:
>>> d1 = {'a': 1, 'b': 2, 'c': 3}
>>> d2 = {'a': 1, 'b': 3, 'c': 3, 'd': 1}
>>> count_common_pairs(d1, d2)
2
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 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']
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 get_length(s): return len(s) def get_indices(s): return range(get_length(s)) def concat(s, n): w = "" for i in get_indices(s): if i % n == 0: w = w + s[i] return w
Given the above script, what are the results of the following expressions:
concat('Whimsy', 2): | ||
concat('Serendipity', 3): |
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')