iter() and next()
Get an iterator from an iterable, and pull its next item (with an optional default).
Easy
it = iter(lines)
header = next(it) # consume the first line
next(it, None) # None instead of StopIteration at the end
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.