NEW
Font size
WorksheetsPython Generators
Total questions: 10
Worksheet time: 5mins
Which of the following is the generator expression?
[x**2 for x in my_list]
(x**2 for x in my_list)
{x**2 for x in my_list}
x**2 for x in my_list
What is the output of the following Python code?
my_list = [1, 3, 6, 10]
list_ = [x**2 for x in my_list]
generator = (x**2 for x in my_list)
print(list_)
print(generator)
list object address and [1, 9, 36, 100]
[1, 9, 36, 100] and list object address
[1, 9, 36, 100] and generator object address
generator object address and [1, 9, 36, 100]
What is the output of the following Python code?
my_list = [2, 4, 9, 14, 17]
value = sum(x**2 for x in my_list)
value
586
59
Error
Nothing is printed
A generator in Python makes use of ________ keyword.
Gen
Return
Yield
All the above
Generator in Python is not a subclass of Iterator.
True
False
State whether the below statement is True or False.
issubclass(collections.Iterator,types.GeneratorType)
True
False
Select the true statement from the below about generators and iterators.
Iterators are implemented using a function as well as class.
Generators are implemented using a function as well as class.
Iterators are implemented using a function, whereas Generators are implemented using a class.
Generators are implemented using a function, whereas iterators are implemented using a class.
Which one of the following is correct?
A dictionary can have two same values with different keys
A dictionary can have two same keys with different values.
A dictionary can have two same keys or same values but cannot have two same key-value pair
A python, a dictionary can neither have two same keys nor two same values.
To obtain the number of entries in dictionary which command is used?
d.size()
size(d)
len(d)
z.len()
