以下代码已经在列表中迭代[sacramento','portland','芝加哥',``纽约'','洛杉矶',“达拉斯”,“亚特兰大”,“迈阿密”]:
for r in nightwatch:
...
for c in r:
...
由于它只是在每个角色中都迭代并为其添加一个空间。
该代码应起作用:
cities = [["Miami", "Atlanta", "Dallas", "Los Angeles"], ["New York", "Chicago", "Portland", "Sacramento"]]
def printList(nightwatch):
for r in nightwatch:
print(r, end=' ')
def flipOrder(listy):
temp = []
for r in range (len(listy)):
for c in range (len(listy[r])):
temp.insert (0, listy[r][c])
listy = temp
printList(listy)
printList(cities)
print ()
print ()
print ()
flipOrder(cities)