In python is there an easier way to write 6 nested for loops?

后端 未结 11 1556
长情又很酷
长情又很酷 2020-12-04 17:49

This problem has been getting at me for a while now. Is there an easier way to write nested for loops in python? For example if my code went something like this

11条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 18:37

    Technically, you could use itertools.product to get a cartesian product of N sequences, and iterate over that:

     for y, x, y1, x1 in itertools.product(range(3), repeat=4):
       do_something_else()
    

    But I don't think that actually wins you anything readability-wise.

提交回复
热议问题