Python multiple for loops

前端 未结 2 1029
感动是毒
感动是毒 2021-01-11 17:24

I am wondering if the 3 for loops in the following code can be written in a better way:

   Nc = 10     # number of points for (0, pi)
   cc1 = linspace(0,pi,         


        
相关标签:
2条回答
  • 2021-01-11 17:57
    import itertools
    
    for a,b,c in itertools.product(cc1, cc2, cc3):
        print a,b,c
    
    0 讨论(0)
  • 2021-01-11 18:00

    try this :)

    [(c1, c2, c3) for c1 in cc1 for c2 in cc2 for c3 in cc3]
    
    0 讨论(0)
提交回复
热议问题