我需要一些帮助来遍历列表列表。我还在学习 Python。
我有一个整数列表,这些整数是更多整数的列表。
例子:
itemWalmart= "food","bread"
itemCostco= "furniture","electronics"
superMarket= walmart,costco
我需要创建一个循环列出项目 + superMarket.Name ,我的问题是当我们向列表中添加更多超级市场和更多项目时。
我想创建一个循环,即使列表增长它也会这样做,所以它会遍历每一个。
列表更大的示例:
itemWalmart= "food","bread"
itemCostco= "furniture","electronics"
itemSoriana= "milk","chocolate"
superMarket= itemWalmart,itemCostco,itemSoriana
我正在尝试的是:
itemWalmart= "food","bread"
itemCostco= "furniture","electronics"
superMarket= itemWalmart,itemCostco
print superMarket
for i in superMarket:
print i + superMarket
我明白了:
# (('food', 'bread'), ('furniture', 'electronics'))
# ('food', 'bread', ('food', 'bread'), ('furniture', 'electronics'))
# ('furniture', 'electronics', ('food', 'bread'), ('furniture', 'electronics'))
我想得到这个:
"food","bread" , itemWalmart
"furniture","electronics" , itemCostco
谢谢