On Fri, 9 Sep 2011 07:19:12 -0500 "Edward K. Ream" <[email protected]> wrote:
> On Thu, Sep 8, 2011 at 7:35 PM, mdb <[email protected]> wrote: > > In a Leo script I find a portion of my outline and create a generator > > > > pa= p.self_and_subtree() > > The Leonine solution is: > > for p2 in p.copy().self_and_subtree(): > > This does not advance p, so you are free later to do whatever you want > with p. The code creates no unnecessary explicit iter object. > Finally, the name p2 (rather than px) is a standard coding convention > that allows more autocompleter completions for "p2.". I don't think p.self_and_subtree() advances p either, at least it didn't appear to just now in a quick test. The OP's issue seemed to be wanting to access the first element of an iterator after you've consumed the iterator, which requires copying it to a list or using itertools.tee or catching the value in iteration 0. In all these cases the need for p2.copy() could probably bite you. But seeing the first element of the iterator is p, which hasn't changed, the question seemed moot. Cheers -Terry -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/leo-editor?hl=en.
