NEW
Font size
WorksheetsTIU Quiz-9
Total questions: 10
Worksheet time: 5mins
What will be the output of the following code?
10
5
lambda x: x * 2
Error
Which of the following is a correct implementation of list comprehension to create a list of squares of numbers from 1 to 5?
[x ** 2 for x in range(1, 6)]
{x ** 2 for x in range(1, 6)}
{x: x ** 2 for x in range(1, 6)}
[x ** 2 in range(1, 6)]
Which of the following is the correct way to sort a list of tuples based on the second element of each tuple in descending order?
sorted(tuples, key=lambda x: x[1], reverse=True)
sorted(tuples, key=lambda x: x[0], reverse=True)
sorted(tuples, key=lambda x: x[1], reverse=False)
sorted(tuples, key=lambda x: x[0], reverse=False)
What is the output of the following code snippet?
2024 5 16
16 5 2024
5 16 2024
Compile Time Error
How can you convert a datetime object into a formatted string representation of the date and time?
str(date_obj)
date_obj.strftime("%Y-%m-%d %H:%M:%S")
date_obj.format("%Y-%m-%d %H:%M:%S")
format(date_obj, "%Y-%m-%d %H:%M:%S")
What does the map() function in Python do?
Applies a function to each element of an iterable
Creates a map object from an iterable
Merges two iterables into one
Sorts elements of an iterable
What will be the output of the following code?
[25, 10, 8]
[25, 10, 8, 15]
[30, 10, 8]
Error
Given a list numbers = [1, 2, 3, 4, 5], what does [x for x in numbers if x % 2 == 0] return?
[1, 3, 5]
[2, 4]
[1, 2, 3, 4, 5]
[4, 2]
Which of the following is NOT a valid way to define an anonymous (lambda) function in Python?
lambda x: x * 2
def(x): return x * 2
lambda x, y: x + y
lambda : "hello"
What is the result of sum([x for x in range(10) if x % 2 == 0])?
20
25
30
None of These
