Write a function which takes a dictionary and another argument, d and a, and returns the value for the key a if it exists, otherwise it returns 'unknown'.
Write a function, borrow_book(user: str, book: str, books: list[str], borrowed: dict[str, str]),
that removes the book from the available books
and adds it to the user's borrowed list if the book is available.
Return a message about the action. Example:
>>> books = ["1984", "The Hobbit"]
>>> borrowed = {}
>>> print(borrow_book("Alice", "1984", books, borrowed))
Book '1984' borrowed by Alice.
>>> borrowed
{'Alice': ['1984']}
>>> books
["The Hobbit"]
Sorry, Of Mice And Men is not available.
Write a function that takes a dictionary and prints all its keys, one per line.
Write a function, return_book(user: str, book: str, books: list[str], borrowed: dict[str, str]),
that moves a book from a user's borrowed list back to the available books.
Return a message about the action. Example:
>>> books = ["1984", "The Hobbit"]
>>> borrowed = {'Alice': ['1984']}
>>> print(return_book("Alice", "1984", books, borrowed))
Book 1984 returned by Alice.
>>> print(return_book("Alice", "The Hobbit", books, borrowed))
Alice did not borrow 'The Hobbit.
Write a function which takes a dictionary and removes all of its items.
Define a function that takes one list of numbers, and modifies it by subtracting 5 from each number.
def sub_list(lst, i, offset):
return lst[i-offset:i]
def element(lst, i, offset):
return lst[i-offset]
t = [1, 2, 3, 4, 5, 6]
t1 = sub_list(t, 4, 1)
t2 = element(t, 4, 1)
| t1: | ||
| t2: |
def dosmth(lst):
for index in range(len(lst) - 1):
lst[index] = lst[index + 1]
lst[-1] = lst[0]
nums = [1, 2, 3, 4]
dosmth(nums)
Complete execution flow of the following program
t = ['pse', 'po', 'ani'] print(t.remove('pse'))
Complete execution flow of the following program
def dosmth(s, i): index = 0 while index < len(s): if index == i: return s[i] index = index + 1 dosmth('pst', 1)