Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
2d_list = [[1,0],[2,0],[3,0]]
从用户获取输入num并添加到第一个元素并将结果保存在第二个元素中并替换第一个列表
num
输入一个整数:2
输出:[[1,3], [2, 4], [3,5]]
[[1,3], [2, 4], [3,5]]
myList = [[1,0],[2,0],[3,0]] num = int(raw_input("Enter a number: ")) newList = [[i[0], i[0]+num] for i in myList]
这可能会更快(由于不分配新空间):
myList = [[1,0],[2,0],[3,0]] num = int(raw_input("Enter a number: ")) for elem in myList: elem[1] = elem[0]+num