【发布时间】:2012-11-19 12:33:33
【问题描述】:
这是一个关于python列表的问题。 (我的编程环境是SL4A with python)
我想要下面的列表,输入数字“n”。
[ ['a'] , [] , [] , [] ] # (this example is the list when n =4) <- the list I want
所以,我在下面写了一个源代码。
n = input()
array = [[]]*n
array[0].append('a')
print array
但是,我不能得到上面的输出,但也能得到一个类似的列表......
[ ['a'], ['a'], ['a'], ['a'] ] # <- wrong list
所以,我有两个问题。
- 请告诉我一个源代码,它是我想要的列表。
- 为什么源代码给了我错误的列表?
【问题讨论】:
-
感谢您编辑我的问题并告诉我一个过去的问题,我应该在发布此问题之前确认。