Saturday, 24 August 2013

Python: Append values to list without for-loop

Python: Append values to list without for-loop

How can I append values to a list without using the for-loop?
I want to avoid using the loop in this fragment of code:
count = []
...
...
for i in range(0, 6):
print "Adding %d to the list." % i
count.append(i)
The result must be:
count = [0, 1, 2, 3, 4, 5]
I tried different ways, but I can't manage to do it.

No comments:

Post a Comment