Rewriting elements in a loop of lists (Python)

Hello. In Python, in a loop of lists, a = [-1] `` `does not rewrite the original list, but a [0] = -1``` Rewrite.

alist = [[0], [0], [0]]
for a in alist:
  a = [-1]

print(alist)  # ==>  [[0], [0], [0]]

for a in alist:
  a[0] = -1

print(alist)  # ==>  [[-1], [-1], [-1]]
$ python3 -V
Python 3.7.7

Recommended Posts

Rewriting elements in a loop of lists (Python)
Group by consecutive elements of a list in Python
Get the number of specific elements in a python list
Display a list of alphabets in Python 3
Draw a graph of a quadratic function in Python
Get the caller of a function in Python
Make a copy of the list in Python
Make a joyplot-like plot of R in python
Output in the form of a python array
Get a glimpse of machine learning in Python
Sort list elements in a specified order in Python
Create a loop antenna pattern in Python in KiCad
A well-prepared record of data analysis in Python
[Python] Manipulating elements in a list (array) [Sort]
Extract elements (using a list of indexes) in a NumPy style from a Python list / tuple
A collection of code often used in personal Python
Get the size (number of elements) of UnionFind in Python
[Python] Outputs all combinations of elements in the list
Display a histogram of image brightness values in python
A collection of Excel operations often used in Python
A reminder about the implementation of recommendations in Python
Take a screenshot in Python
Create a function in Python
Create a dictionary in Python
Equivalence of objects in Python
Make a bookmarklet in Python
Draw a heart in Python
Implementation of quicksort in Python
Getting list elements in Python
How to check in Python if one of the elements of a list is in another list
Find out the apparent width of a string in python
[python] Summary of how to retrieve lists and dictionary elements
Loop through a generator that returns a date iterator in Python
Make a table of multiplication of each element in a spreadsheet (Python)
How to develop in a virtual environment of Python [Memo]
[Note] Import of a file in the parent directory in Python
How to get a list of built-in exceptions in python
A memo of writing a basic function in Python using recursion
A set of script files that do wordcloud in Python3
Find the eigenvalues of a real symmetric matrix in Python
A record of patching a python package
Maybe in a python (original title: Maybe in Python)
Pixel manipulation of images in Python
Write a binary search in Python
A good description of Python decorators
python web scraping-get elements in bulk
[python] Manage functions in a list
Hit a command in Python (Windows)
[Python] A memorandum of beautiful soup4
Draw a scatterplot matrix in python
Division of timedelta in Python 2.7 series
A brief summary of Python collections
ABC166 in Python A ~ C problem
MySQL-automatic escape of parameters in python
Write A * (A-star) algorithm in Python
Handling of JSON files in Python
Implementation of life game in Python
Create a binary file in Python
Waveform display of audio in Python
Solve ABC036 A ~ C in Python
Write a pie chart in Python