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']
Use dictionaries get method to write histogram more concisely. You should be able to eliminate the if statement.
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 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 dictionary whose values are strings, and returns sum of length
all of values.
Example:
>>> get_string({1: "ani", 2: "o", -1: "pse"})
7
def dosmth(s, chars):
res = 0
for index in range(len(s)):
if s[index] in chars:
res = index + res
return res
Given the above script, what are the results of the following expressions:
| dosmth('ani', 'ni'): | ||
| dosmth('psejo', 'eo'): |
def dosmth(s, char):
c = 0
for i in range(len(s)):
if s[i] == char:
c = c + i
return c
Given the above script, what are the results of the following expressions:
| dosmth('baba', 'b'): | ||
| dosmth('nana', 'a'): |
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)