简体   繁体   English

在两个地方列出更新

[英]List updates in two places

In python you can create a list like so: 在python中,您可以像这样创建一个列表:

[[0,0]]*n

This creates a list such as this: 这将创建如下列表:

[[0, 0], [0, 0], [0, 0]]

The issue is when you update the list such as: 问题是当您更新列表时,例如:

li[0][0]=10
[[10, 0], [10, 0], [10, 0]]

Is there anyway to create lists of a certain size with this method but not encountering this problem? 无论如何,使用这种方法可以创建一定大小的列表,但不会遇到此问题吗?

I created this workaround but is there a better way? 我创建了此替代方法,但是有更好的方法吗?

for x in range(players):
    li+=[[0]*n]
li = [[0,0] for i in range(players)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM