Nested for loops in Python

后端 未结 3 871
灰色年华
灰色年华 2021-01-05 10:32

I want to do something like

for a in [0..1]:
    for b in [0..1]:
        for c in [0..1]:
            do something

But, I might have 15 di

3条回答
  •  迷失自我
    2021-01-05 11:26

    itertools.product:

    import itertools
    for a,b,c in itertools.product([0, 1], repeat=3):
      # do something
    

提交回复
热议问题