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 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 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 string and returns a dictionary with string elements (letters)
as values and their corresponding indices as keys.
>>> create_dictionary('ani')
{0: 'a', 1: 'n', 2: 'i'}
Write a function, get_most_active_user, that takes the borrowed dictionary
and returns the user who borrowed the most books.
If there are multiple users with the same maximum, return any one of them. Example:
>>> borrowed = {"Alice": ["1984", "The Hobbit"], "Bob": ["Python"]}
>>> get_most_active_user(borrowed)
'Alice'
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'}
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'): |
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 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)