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/2003-November/040533.html below:

[Python-Dev] "groupby" iterator

[Python-Dev] "groupby" iterator [Python-Dev] "groupby" iteratorGuido van Rossum guido at python.org
Sun Nov 30 11:50:41 EST 2003
I lost David Eppstein's post, but I finally know what I want to say in
response.  David objected to the behavior of the groupby()
subiterators to become invalidated when the outer iterator is moved on
to the next subiterator.  But I don't think there's a good use case
for what he wants to do instead: save enough state so that the
subiterators can be used in arbitrary order.  An application
that saves the subiterators for later will end up saving a copy of
everything, so it might as well be written so explicitly, e.g.:

  store = {}
  for key, group in groupby(keyfunc, iterable):
      store[key] = list(group)
  # now access the groups in random order:
  for key in store:
      print store[key]

I don't think the implementation should be complexified to allow
leaving out the explicit list() call in the first loop.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list

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