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 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, process_text, that takes a string and:
- Replaces all punctuation with spaces
- Converts the string to lowercase
- Splits the string into words
- Returns a dictionary with word frequencies
>>> process_text("Hello, world! Hello again.")
{'hello': 2, 'world': 1, 'again': 1}
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, 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, d, whose keys are numbers and values are strings
and returns a new dictionary by adding 2 to each key and '!' to each value. Example:
>>> add_to_dict({1: 'a', 4: 'jo be'})
{3: 'a!', 6: 'jo be!'}
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 update(lst, i, j):
lst[i] = lst[j][i] + 1
nums = [[0, 0], [1, 1], [2, 2]]
update(nums, 1, 1)
print(nums)
update(nums, -1, 0)
print(nums)
Given the above script, write the printed values in the order that they appear.
| 1: | ||
| 2: |
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)