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, 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 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
"users": {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"},
"Avatar": {"rating": 8, "review": "Immersive"}
},
"Charlie": {
"Inception": {"rating": 10, "review": "Amazing"},
"Titanic": {"rating": 6, "review": "Emotional"},
"Avatar": {"rating": 7, "review": "Nice"}
}
}
Write a function, get_similarity(user1: str, user2: str, users: dict),
that returns a similarity score between two users based on ratings of common movies.
Use the sum of absolute differences in rating (lower score = more similar).
If no common movies, return None. Example:
>>> get_similarity("Alice", "Charlie", users)
3 # |9-10| + |7-6| + |8-7| = 1+1+1 = 3
Write a function that takes a list and two integers, t, i and j changes t elements from
index i to index j (including i not including j) with None
>>> a = [4, 3, 1, 2, 'ani', 'po']
>>> change_list(a, 1, 4)
>>> a
[4, None, None, None, 'ani', 'po']
Write a function that takes a list and returns a new list which is reverse of the input list.
>>> a = [4, 3, 1, 2]
>>> d = reverse_list(a)
[2, 1, 3, 4]
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 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')