-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy49.py
More file actions
22 lines (17 loc) · 859 Bytes
/
py49.py
File metadata and controls
22 lines (17 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#list comprehension
x=[[i,i] for i in range(5)]#nested list
print(x) #[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]
y=[i for i in range (5)]
print(y) #[0, 1, 2, 3, 4]
h=[[i] for i in range (5)] # for nested list [[i]]
print(h) #[[0], [1], [2], [3], [4]]
z=[[i,j] for i in range(5) for j in range(3)]#nested list
print(z) #[[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0],
# [2, 1], [2, 2], [3, 0], [3, 1], [3, 2], [4, 0], [4, 1], [4, 2]]
n=5
u,v,w=1,2,3
l=[[p,q,r] for p in range(u+1) for q in range(v+1) for r in range(w+1) if (p+q+r)!=n] #giving condition
print(l) #[[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 0, 3], [0, 1, 0],
# [0, 1, 1], [0, 1, 2], [0, 1, 3], [0, 2, 0], [0, 2, 1], [0, 2, 2],
# [1, 0, 0], [1, 0, 1], [1, 0, 2], [1, 0, 3], [1, 1, 0], [1, 1, 1],
# [1, 1, 2], [1, 2, 0], [1, 2, 1], [1, 2, 3]]