Write a function that takes a list of integers, t, and returns a new list which contains only
even integers of t.
>>> a = [4, 3, 1, 2, 5, 2]
>>> d = get_evens(a)
>>> d
[4, 2, 2]
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
[]
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!'}
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 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
def dosmth(s, chars):
res = ""
for letter in s:
if letter in chars:
res = res + letter
return len(res)
Given the above script, what are the results of the following expressions:
| dosmth('python programming', 'pom'): | ||
| dosmth('python programming', 'arr'): |
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'): |
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')