Reputation: 55
Say I have an array thusly:
a = [1, 2, 3, 4]
I want to have it be printed like so:
1
2
3
4
but I don't want to go:
print(a[0])
print(a[1])
print(a[2])
print(a[3])
I want it to automatically print each entry, but dynamically enough so that it stops when there is nothing more, but keeps going if there is, if that makes any sense. I'm not very good at words when it comes to programming, but I hope this makes sense.
Upvotes: 0
Views: 2648
Reputation: 35907
Obligatory Python3 answer:
[print(k) for k in a]
print
is a function in Python3.
Upvotes: 1