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'
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 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 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
Write a function that takes a list of integers, t, it returns sum of all integers and deletes all
elements from t.
>>> a = [4, 3, 1, 2, 5, 2]
>>> d = get_sum(a)
>>> d
17
>>> a
[]
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): |
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)