Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing an array with a range in Python3.x

Tags:

python

Let's assume I want to write a row in a csv file. This row will be something like:

name,last_name,birthday,hobby1,hobby2,hobby3, ... , hobby200 

I can create an array like ['name', 'last_name' .... ] but is there any possible way to set a range o


1 Answers

I assume you want this

List = ['name', 'last name', 'birthday']
List = List + ['hobby%d' %i for i in range(200)]
print(List)

output

['name', 'last name', 'birthday', 'hobby0', 'hobby1', 'hobby2', ....., 'hobby199']

if you don't want 0, and want 200 do range(1, 201)

like image 66
12ksins Avatar answered Jan 31 '26 22:01

12ksins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!