How to iterate a sequence, with skipping the first item?

Paul Rubin http
Tue Aug 12 09:02:06 CEST 2008

ray <hanlray at> writes:
> for x in container.iterChildren():
> How to skip the first item? It seems that it's a simple question.
> Could somebody help me? Thanks.

First solution:

    c = container.iterChildren()    # skip first item
    for x in c: ...

Second solution:

    from itertools import islice
    for x in islice(container.iterChildren(), 1, None): ...

I like the second solution better but it's a matter of preference.

More information about the Python-list mailing list