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 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 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 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 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 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']
ⓘ
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): |
def dosmth(line): count = 0 i = 1 while i < len(line): if line[i - 1] == line[i]: count = count + 1 i = i + 1 return count
Given the above script, what are the results of the following expressions:
dosmth('address'): | |
dosmth('apple'): | |
dosmth('pse'): |
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')