相关疑难解决方法(0)

如何在Python中使for循环金字塔更简洁?

在固体力学中,我经常使用Python并编写如下所示的代码:

for i in range(3):
    for j in range(3):
        for k in range(3):
            for l in range(3):
                # do stuff
Run Code Online (Sandbox Code Playgroud)

我经常这样做,我开始怀疑是否有更简洁的方法来做到这一点.当前代码的缺点是:如果我遵守PEP8,那么我不能超过每行79个字符的限制,并且没有太多的空间,特别是如果这又是一个类的功能.

python performance python-2.7 python-3.x

62
推荐指数
4
解决办法
3758
查看次数

标签 统计

performance ×1

python ×1

python-2.7 ×1

python-3.x ×1