开发者

List updates in two places

In python you can create a list like so:

[[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]开发者_如何学Python, [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)]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜