Python 多重 for 循环

标签 python

我想知道是否可以用更好的方式编写以下代码中的 3 个 for 循环:

   Nc = 10     # number of points for (0, pi)
   cc1 = linspace(0,pi,Nc)
   cc2 = linspace(0,pi/2,Nc/2)
   cc3 = linspace(0,pi/2,Nc/2)
   for c1 in cc1:
       for c2 in cc2:
           for c3 in cc3:
               print c1,c2,c3

最佳答案

import itertools

for a,b,c in itertools.product(cc1, cc2, cc3):
    print a,b,c

关于Python 多重 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12032185/

相关文章:

Python format() 传递一个对象

Python 多处理队列、管道、共享内存

python - 从具有负值和正值的 Pandas 数据框中绘制

python - 跟踪玩家健康基于文本的游戏 - Python

python - 在 Python 中忽略来自第三方包的日志消息

python - 传输错误 : TransportError(503, 'search_phase_execution_exception' )

python - 外部加入 python Pandas

python - 如何找出哪些字符被定义为给定语言环境的字母数字

python - 使用 python,自动确定用户当前时区的最准确方法是什么

Python-eve GET 响应不包含资源内容(除非我指定它的模式)