Write a function that takes a list of strings and returns sum of length of each string.
Example:
>>> get_length(["You", "talking", "to", "me", "?"])
15
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 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 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']
users = {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"},
"The Matrix": {"rating": 10, "review": "Revolutionary sci-fi"}
},
"Bob": {
"Inception": {"rating": 8, "review": "Loved the visuals"},
"Interstellar": {"rating": 10, "review": "Masterpiece"},
"The Dark Knight": {"rating": 9, "review": "Best superhero movie"}
},
"Charlie": {
"Titanic": {"rating": 9, "review": "Very emotional"},
"Avatar": {"rating": 8, "review": "Visually stunning"},
"Gladiator": {"rating": 9, "review": "Epic historical drama"}
}
}
Write a function, suggest_movie(user: str, users: dict) that suggests a movie
to a user based on what similar users have rated highly,
which the current user hasn't rated. Use the user with the lowest similarity score. Example:
>>> suggest_movie("Alice", users)
"Interstellar"
>>> suggest_movie("Bob", users)
"The Matrix"
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}
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)