Help
Contact
For teachers and institutes
Search courses, problems, tests…
A
A
>_
StemPy Lab
Courses ▾
Problems ▾
Practice ▾
Mock Tests
Classes
Groups
Community ▾
A
A
Problems
/
Python Going Further
/
Comprehensions, Iterators and Generators
Comprehensions, Iterators and Generators
Python Programming
+ Upload a Problem
More in Python Going Further
Classes and Objects
Inheritance and Special Methods
Files and Data Formats
Comprehensions, Iterators and Generators
Data Structures
Testing and Debugging
All Levels
High School (9–10)
High School (11–12)
Undergraduate
General
All
Easy
Medium
Hard
Sort
Mixed
Newest first
Oldest first
A to Z
11 problems
Type:
Any
Conceptual
Python-Coded
1.
Write an endless generator primes() that gives 2, 3, 5, 7, 11,...
High School (11–12), High School (9–10), Undergraduate, General · Comprehensions, Iterators and Generators
StemPy Lab
Hard
2.
Write an endless generator squares() that gives 1, 4, 9, 16,...
High School (11–12), High School (9–10), Undergraduate, General · Comprehensions, Iterators and Generators
StemPy Lab
Medium
3.
Follow the generator
High School (11–12), High School (9–10), Undergraduate, General · Comprehensions, Iterators and Generators
StemPy Lab
Medium
4.
Used up
High School (11–12), High School (9–10), Undergraduate, General · Comprehensions, Iterators and Generators
StemPy Lab
Medium
5.
For each, say whether it is an iterable that is not an iterator, or an iterator, and whether it can…
High School (11–12), High School (9–10), Undergraduate, General · Comprehensions, Iterators and Generators
StemPy Lab
Easy
6.
A list of pairs students = [("Asha", 72), ("Ravi", 85), ("Meera", 72), ("Kabir", 90)].
High School (11–12), High School (9–10), Undergraduate, General · Comprehensions, Iterators and Generators
StemPy Lab
Medium
7.
Any or all?
High School (11–12), High School (9–10), Undergraduate, General · Comprehensions, Iterators and Generators
StemPy Lab
Easy
8.
Given names = ["Asha", "Ravi", "Meera"] and marks = [72, 85, 64], use zip and a comprehension to…
High School (11–12), High School (9–10), Undergraduate, General · Comprehensions, Iterators and Generators
StemPy Lab
Easy
9.
The matrix is m = [[1, 2], [3, 4], [5, 6]], three rows of two.
High School (11–12), High School (9–10), Undergraduate, General · Comprehensions, Iterators and Generators
StemPy Lab
Medium
10.
Write this comprehension as a plain loop, and say what it gives for numbers = [1, 2, 3, 4, 5].
High School (11–12), High School (9–10), Undergraduate, General · Comprehensions, Iterators and Generators
StemPy Lab
Easy
11.
Write each loop as a list comprehension.
High School (11–12), High School (9–10), Undergraduate, General · Comprehensions, Iterators and Generators
StemPy Lab
Easy