Explore Connect Documentation
Snippets

Computing with Data

elgeish
347.4K views
GitHub

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content
Previous: Dictionary Comprehensions Next: Control Flow

Nested Comprehensions

Comprehensions can be nested; the expression that evaluates to an element in the result can be a comprehension:

1
2
3
4
# create a 3x5 matrix of 1's
matrix = [[1 for j in range(5)] for i in range(3)]
print(matrix)
Enter to Rename, Shift+Enter to Preview
Suggested playgrounds

Python Hello World program

By
SJTECollege
2,316
137
6

Correct the code to display 'Hello World!'

By
SJTECollege
3,037
135
3

Les bases de Python pour le lycée

By
smalicet
4,014
11
0

Tuesday Night Python - Weekly Challenge 001

By
4candles
1,280
45
5
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content