This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年02月02日 00:40 by drathlian, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| twoDimensionalList.py | drathlian, 2012年02月02日 00:40 | |||
| Messages (2) | |||
|---|---|---|---|
| msg152450 - (view) | Author: Dave E (drathlian) | Date: 2012年02月02日 00:40 | |
I might be missing something, but I am expecting the following code to print out a list of lists with each internal list holding one number[0-4], but instead the internal lists are a copy of the list "count". #!/usr/bin/python count = range(4) twoDimensionList = [[]] * len(count) for i in range(len(count)): twoDimensionList[i].append(count[i]) print twoDimensionList Should print: [[0], [1], [2], [3]] but erroneously prints: [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]] |
|||
| msg152451 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2012年02月02日 00:47 | |
This isn't a bug, but a known gotcha: see. http://docs.python.org/faq/programming.html#how-do-i-create-a-multidimensional-list |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:26 | admin | set | github: 58133 |
| 2012年02月02日 00:47:08 | mark.dickinson | set | status: open -> closed nosy: + mark.dickinson messages: + msg152451 resolution: not a bug |
| 2012年02月02日 00:40:48 | drathlian | create | |