Best way to check that you are at the beginning (the end) of an iterable?
laurent.payot at gmail.com
Wed Sep 7 23:35:41 CEST 2011
What is the simplest way to check that you are at the beginning or at the end of an iterable? I'm using enumerate with Python 3.2 (see below) but I'm wondering if there would be a better way.
l = ['a', 'b', 'a', 'c']
for pos, i in enumerate(l):
if pos == 0:
print("head =", i)
I know that Python is not exactly a functional language but wouldn't something like "ishead()" or "istail()" be useful?
More information about the Python-list