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
Use dictionaries get method to write histogram more concisely. You should be able to eliminate the if statement.
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 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, 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 a dictionary and returns sum of all integers (whether they are
keys or values).
Example:
>>> get_sum({1: 'a', 2: 6, 12: 'po', 'jo': 4})
25
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')