Possible Duplicate:
“Least Astonishment” in Python: The Mutable Default Argument
Python - Using the Multiply Operator to Create Copies of Objects in Lists
Python behaves unexpected when i append to a list, which is in another list. Here's an example:
>>> _list = [[]] * 7
>>> _list
[[], [], [], [], [], [], []]
>>> _list[0].append("value")
What i expect:
>>> _list
[['value'], [], [], [], [], [], []]
What i get:
>>> _list
[['value'], ['value'], ['value'], ['value'], ['value'], ['value'], ['value']]
Why is this? how can i go around it?