A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-July/026592.html below:

[Python-Dev] Single- vs. Multi-pass iterability

[Python-Dev] Single- vs. Multi-pass iterability [Python-Dev] Single- vs. Multi-pass iterabilityDavid Abrahams David Abrahams" <david.abrahams@rcn.com
Mon, 15 Jul 2002 20:39:22 -0400
From: "Andrew Koenig" <ark@research.att.com>

> >> A data structure that supports several different kinds of iteration
> >> has to provide that support somehow.  What's your suggestion?
> 
> David> class DataStructure(object):
> David>     def __init__(self):
> David>         self._numbers = range(10);
> David>         self._names = [ str(x) for x in range(10) ];
> 
> David>     names = property(lambda self: iter(self._names))
> David>     numbers = property(lambda self: iter(self._numbers))
> 
> David> x = DataStructure();
> David> for y in x.names:
> David>     print repr(y),
> 
> David> print
> 
> David> for y in x.numbers:
> David>     print repr(y),
> 
> David> [Y'know, Python is great. That worked the first time I ran it.]
> 
> I don't understand how this code answers my question.
> You've asked for iterators over two different data structures.
> What I was asking was, for example, how one might arrange for a single
> tree to yield either a depth-first or breadth-first iterator.

Just replace 'names' by breadth_first and 'numbers' by depth_first.

or-vice-versa-ly y'rs,
dave





RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4