Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcut for creating a list with many repeating Boolean values

Tags:

python

If I want to make a list consisting of 12 False Boolean values, is there a shortcut to do this without typing out all 12? I know that 'string ' * 3 returns 'string string string'. But True * 3 just returns 3.

like image 656
collinksmith Avatar asked Nov 01 '25 18:11

collinksmith


1 Answers

You need to put whatever you're repeating in an array, and then multiply by an integer to get repeating sequence.

x = [False] * 12 should work.

like image 88
Haleemur Ali Avatar answered Nov 04 '25 09:11

Haleemur Ali