Python nested looping Idiom

后端 未结 4 1468
北海茫月
北海茫月 2020-11-30 07:27

I often find myself doing this:

for x in range(x_size):
    for y in range(y_size):
        for z in range(z_size):
            pass # do something here
         


        
4条回答
  •  醉酒成梦
    2020-11-30 08:04

    It depends on what is inside the loop. If dealing with lists, you may be able to use a list comprehension

    For the more general case, see this post on itertools.

提交回复
热议问题