Reputation:
How do I write this code snippets easier or in one line?
dist=[]
for k in range(5):
dist.append(k)
dist[0]="Apple"
print(dist)
Upvotes: 0
Views: 41
Reputation: 1122
Python 2.7 (works in Python 3+ as well):
>>> dist = ['Apple'] + [i for i in range(1,5)]
>>> dist
['Apple', 1, 2, 3, 4]
Upvotes: 1