2025-2026
reverse list in Python - Answers [::-1]
join list in Python - Answers ''.join([list])
return the largest integer not greater than x - Answers math.floor()
return the smallest integer not less than x - Answers math.ceil()
python round call - Answers round(x, 2); first argument is the number and the second argument
is the precision after the decimal point
list comprehension with if-else statement - Answers [f(x) if condition else g(x) for x in sequence]
list comprehension with if statement - Answers [f(x) for x in sequence if condition]
create a tuple - Answers tuple((x, y, z)) OR (x, y, z)
get index in list comprehension - Answers [i for i, x in enumerate(L) if x <= threshold]
check if list (L) is empty - Answers if not L:
get unique values in list [1, 1, 2, 3, 3, 4] - Answers set([1, 1, 2, 3, 3, 4])
get first item in list of lists (lst) - Answers [item[0] for item in lst]
convert a list of strings (test_list) into integers using map - Answers test_list = list(map(int,
test_list))
lambda function sum *args - Answers (lambda *args: sum(args))(1,2,3)
lambda function sum **kwargs - Answers (lambda **kwargs: sum(kwargs.values()))(one=1,
two=2, three=3)
*args - Answers arguments
**kwargs - Answers key word arguments
Unpacking With the Asterisk Operators: * & ** - Answers The single asterisk operator * can be
used on any iterable that Python provides, while the double asterisk operator ** can only be
used on dictionaries.
place variables name and age in string with f-string - Answers f"Hello, {name}. You are {age}."
create a dictionary from the string 'letters' with letters and corresponding letter counts -
Answers {letter : word.count(letter) for letter in set (word)}