Y
Y
YraganTron2014-09-24 12:34:50
Python
YraganTron, 2014-09-24 12:34:50

How to create a list like [0,1...n]?

The bottom line is that I have a function that needs to be given some value as input. Inside this function, I have a list and, depending on the input value, it should change the length. Those. initially I have a list [0,1]
I give as input 6 receive a list [0,1,0,0,0,0]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Tiunov, 2014-09-24
@YraganTron

Such a list can be obtained using list comprehensions
your_list = [i for i in range(n)]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question