Created
August 19, 2018 05:18
-
-
Save turing4ever/6afcbee4df955ee14ac1dac1eccc2a25 to your computer and use it in GitHub Desktop.
Duplicate a list in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if e is immutable | |
[e] * n | |
# [e] is mutable | |
list_of_list = [[e] for _ in range(n)] | |
# if you do [e] * n, you will get n references to the same [e] | |
foo = [[]] *4 | |
foo[0].append('x') | |
[['x'], ['x'], ['x'], ['x']] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment