For loop in for loop Python [closed]

2020-05-10 15:13发布

I need to write for loop in for loop for my Python pragramme,

I know writing that in C, but I dont have any idea about python

I tried but I cannot manage that

Please rise me up ,

2条回答
姐就是有狂的资本
2楼-- · 2020-05-10 15:38

Simple, just do nested for-loops. Can't get any easier :D

L = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]
for i in L:
    for j in i:
        print j

Prints:

1
2
3
4
5
6
7
8
9

If you want to iterate over two lists, use zip():

a = [1, 2, 3]
b = [4, 5, 6]
for i, j in zip(a, b):
    print i, j

Prints:

1 4
2 5
3 6
查看更多
▲ chillily
3楼-- · 2020-05-10 15:49

maybe you should give us more info about what you'r trying to do. any way this how its done:

for i1 in range(0,10):
     for i2 in range(0,10):
         print i1, i2
查看更多
登录 后发表回答