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 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 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 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']
Write a function that takes a dictionary, d, whose keys are numbers and values are strings
and returns a new dictionary by adding 2 to each key and '!' to each value. Example:
>>> add_to_dict({1: 'a', 4: 'jo be'})
{3: 'a!', 6: 'jo be!'}
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
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 dosmth(s, i):
index = 0
while index < len(s):
if index == i:
return s[i]
index = index + 1
Given the above script, what are the results of the following expressions:
| dosmth('ani', 2): | ||
| dosmth('pse', 1): | ||
| dosmth('po', 5): |
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')