首页 > 解决方案 > 如何遍历多个列表以返回具有良好语法的元组

问题描述

我想以最简洁的方式编写这段代码:

def test_roomVolume(self):
        widths = [4, 1, 4, 4, 1, 4, 1, 1]
        lengths = [4, 4, 1, 4, 1, 1, 4, 1]
        heights = [4, 4, 4, 1, 4, 1, 1, 1]
        expected = [64, 0, 0, 0, 0, 0, 0, 0]
        for i in range(len(widths)):
            dimensions = (widths[i], lengths[i], heights[i])

有没有更好的方法来创建维度元组?喜欢

dimensions = (widths, lengths, heights)[i]

类似的东西?

标签: pythoniteration

解决方案


推荐阅读