Things to note when initializing a list in Python

list1 = list2 = [] If it is initialized like this, the reference will be copied. Don't panic, don't rush list1 = [] list2 = [] Should be like

test.py


>>> list1 = list2 = []
>>> list1.append(1)
>>> list2.append(2)
>>> print list1
[1, 2]

Recommended Posts

Things to note when initializing a list in Python
How to clear tuples in a list (Python)
Python Note: When assigning a value to a string
Things to keep in mind when copying Python lists
Things to keep in mind when processing strings in Python2
Things to keep in mind when processing strings in Python3
When creating a matrix in a list
When writing a program in Python
[python] A note when trying to use numpy with Cython
Developed a library to get Kindle collection list in Python
Convenient writing method when appending to list continuously in Python
How to get the last (last) value in a list in Python
How to get a list of built-in exceptions in python
Things to keep in mind when using Python with AtCoder
Things to keep in mind when using cgi with python.
Precautions when pickling a function in python
Try to get a list of breaking news threads in Python.
[Python] How to convert a 2D list to a 1D list
Display a list of alphabets in Python 3
Things to note when running Python on EC2 from AWS Lambda
Timezone specification when converting a string to datetime type in python
How to get a stacktrace in python
How to delete multiple specified positions (indexes) in a Python list
When I got a list of study sessions in Python, I found something I wanted to make
Things to watch out for when creating a Python environment on a Mac
Note: [Python3] Convert datetime to a string in any format you like
How to write a string when there are multiple lines in python
How to format a list of dictionaries (or instances) well in Python
A note I looked up to make a command line tool in Python
A useful note when using Python for the first time in a while
What to do when a warning message is displayed in pip list
[Python] List Comprehension Various ways to create a list
3 ways to parse time strings in python [Note]
Try to calculate a statistical problem in Python
To execute a Python enumerate function in JavaScript
How to embed a variable in a python string
I want to create a window in Python
How to create a JSON file in Python
Make a copy of the list in Python
A note on optimizing blackbox functions in Python
A clever way to time processing in Python
Note on encoding when LANG = C in Python
Steps to develop a web application in Python
View drug reviews using a list in Python
Data analysis in Python: A note about line_profiler
A simple Pub / Sub program note in Python
To add a module to python put in Julialang
How to notify a Discord channel in Python
[Python] How to draw a histogram in Matplotlib
A python amateur tries to summarize the list ②
Sort list elements in a specified order in Python
Error when trying to install psycopg2 in Python
[Python] Manipulating elements in a list (array) [Sort]
How to remove duplicate elements in Python3 list
Sorted list in Python
Filter List in Python
List find in Python
Note to daemonize python
How to pass the execution result of a shell command in a list in Python
What to do when a warning appears around Python integration in Neovim's CheckHealth
Output timing is incorrect when standard (error) output is converted to a file in Python