Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

initialize boolean list of size python

>>> [False] * 10
[False, False, False, False, False, False, False, False, False, False]
Comment

initialize boolean list of size python

You can do it like this: -

>>> [False] * 10
[False, False, False, False, False, False, False, False, False, False]
NOTE: - Note that, you should never do this with a list of mutable types with same value, else you will see surprising behaviour like the one in below example: -

>>> my_list = [[10]] * 3
>>> my_list
[[10], [10], [10]]
>>> my_list[0][0] = 5
>>> my_list
[[5], [5], [5]]
As you can see, changes you made in one inner list, is reflected in all of them.
Comment

PREVIOUS NEXT
Code Example
Python :: combining list alternatively 
Python :: divide array into equal parts/slices python 
Python :: missing number 
Python :: python merge two byte files 
Python :: pivot_table value aggfunct 
Python :: re mobile no validate python 
Python :: python remove middle of string 
Python :: python lane angle detection 
Python :: onetomany field 
Python :: delete csr python 
Python :: pip install matplotlib.pyplot 
Python :: Optimize images in python using pillow 
Python :: what is type 
Python :: using a print function 
Python :: assertRaises property 
Python :: plt force axis numbers 
Python :: pandas read csv read all columns except few columns 
Python :: how to sum 2 no.s in python 
Python :: python check for int 
Python :: how to make an application using python 
Python :: length of a list python 
Python :: python array sum 
Python :: docker python 3.11 
Python :: c to python converter 
Python :: Adding new column to existing DataFrame in Pandas 
Python :: how to make a screen in pygame 
Python :: python 3d software 
Python :: how to create template folder in django 
Python :: where python packages are installed 
Python :: create a list of the keys in python dictionary 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =