Noah Clark
Noah Clark

Reputation: 8131

Auto Increment While Building list in Python

Here is what I have so far. Is there anyway, I can auto increment the list while it is being built? So instead of having all ones, I'd have 1,2,3,4....

possible = []
possible = [1] * 100
print possible

Thanks, Noah

Upvotes: 1

Views: 5467

Answers (2)

Tony Veijalainen
Tony Veijalainen

Reputation: 5565

Something like this?

start=1
count= 100
possible = [num for num in range(start,start+count)]
print possible

Upvotes: 0

Thomas
Thomas

Reputation: 182093

possible = range(1, 101)

Note that the end point (101 in this case) is not part of the resulting list.

Upvotes: 13

Related Questions