Re: unpacking first few items of iterable

Discussion in 'Python' started by Ian Kelly, Dec 13, 2012.

  1. Ian Kelly

    Ian Kelly Guest

    On Thu, Dec 13, 2012 at 1:39 PM, Daniel Fetchinson
    <> wrote:
    >> If you know the sequence has at least n items, you
    >> can do a, b, c = seq[:3]

    >
    > Yeah, that's probably the simplest, without all the fancy stuff :)


    That only works for sequences, though. Not all iterables are
    sequences. The islice version proposed by MRAB is more generally
    applicable.
     
    Ian Kelly, Dec 13, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Fetchinson

    unpacking first few items of iterable

    Daniel Fetchinson, Dec 13, 2012, in forum: Python
    Replies:
    0
    Views:
    137
    Daniel Fetchinson
    Dec 13, 2012
  2. Demian Brecht

    Re: unpacking first few items of iterable

    Demian Brecht, Dec 13, 2012, in forum: Python
    Replies:
    0
    Views:
    141
    Demian Brecht
    Dec 13, 2012
  3. MRAB
    Replies:
    0
    Views:
    150
  4. Daniel Fetchinson

    Re: unpacking first few items of iterable

    Daniel Fetchinson, Dec 13, 2012, in forum: Python
    Replies:
    0
    Views:
    150
    Daniel Fetchinson
    Dec 13, 2012
  5. Mitya Sirenef

    Re: unpacking first few items of iterable

    Mitya Sirenef, Dec 13, 2012, in forum: Python
    Replies:
    0
    Views:
    142
    Mitya Sirenef
    Dec 13, 2012
Loading...

Share This Page