[TriPython] mnemonic?

Mark Hutchinson aikimark at aol.com
Mon Dec 28 11:12:01 EST 2020


Does anyone know a good mnemonic to help remember/teach about iterables and iterators/generators?
I was thinking about using something like"Jenny, I got your number, but what is your intent?"
But that really doesn't cover it.
Question Context:James Powell gave 26 lightning talks during the end-of-year numFOCUS telethon.  Each topic was a letter of the alphabet.  Since the moderator gave James the actual topic, this was pretty impressive.  His last talk was the Zip function.  He created/shared a way to easily window your iterable data.https://youtu.be/gzbmLeaM8gs?t=15661

I wrote James and said "thanks."  I also suggested what I thought might be a simpler version of his nwise function, not using the tee() function.  
nwise2 = lambda g, n=2: zip(*(islice(g, idx, None)                               for idx in range(n)))
James's response was that he wrote for the general case and that it covers iterables that are not iterators, such as generators.
`nwise` is a general solution to finding overlapping windows from any iterable. If provided an iterator (e.g., a generator instance) then the use of `itertools.tee` is mandatory, irrespective of whether the underlying iterable is concrete or has memory. 
`nwise` is intended to work with non-concrete or memory-less or otherwise non-rewindable iterables (e.g., generators,) but this is not the narrowest requirement leading to `itertools.tee`.
Since `range(10)` is an iterable (but, by itself, not an iterator,) then each `islice` will create its own `range_iterator`, in which case you would not need to `tee`

Palm to forehead moment.  Of course my simpler function worked, but I haven't learned to see iterables the way I need to see them.  I don't differentiate them.  I'm hoping to find a mnemonic to help compensate for that.
Happy Holidays
Stay safe
Mark Hutchinson
-------------- next part --------------
   Does anyone know a good mnemonic to help remember/teach about iterables
   and iterators/generators?
   I was thinking about using something like
   "Jenny, I got your number, but what is your intent?"
   But that really doesn't cover it.
   Question Context:
   James Powell gave 26 lightning talks during the end-of-year numFOCUS
   telethon.  Each topic was a letter of the alphabet.  Since the moderator
   gave James the actual topic, this was pretty impressive.  His last talk
   was the Zip function.  He created/shared a way to easily window your
   iterable data.
   https://youtu.be/gzbmLeaM8gs?t=15661
   I wrote James and said "thanks."  I also suggested what I thought might be
   a simpler version of his nwise function, not using the tee() function.  
   nwise2 = lambda g, n=2: zip(*(islice(g, idx, None) 
                                 for idx in range(n)))
   James's response was that he wrote for the general case and that it covers
   iterables that are not iterators, such as generators.

     `nwise` is a general solution to finding overlapping windows from any
     iterable. If provided an iterator (e.g., a generator instance) then the
     use of `itertools.tee` is mandatory, irrespective of whether the
     underlying iterable is concrete or has memory. 
     `nwise` is intended to work with non-concrete or memory-less or
     otherwise non-rewindable iterables (e.g., generators,) but this is not
     the narrowest requirement leading to `itertools.tee`.
     Since `range(10)` is an iterable (but, by itself, not an iterator,) then
     each `islice` will create its own `range_iterator`, in which case you
     would not need to `tee`

   Palm to forehead moment.  Of course my simpler function worked, but I
   haven't learned to see iterables the way I need to see them.  I don't
   differentiate them.  I'm hoping to find a mnemonic to help compensate for
   that.
   Happy Holidays
   Stay safe
   Mark Hutchinson


More information about the TriZPUG mailing list