Re: A problem with itertools.groupby

2021-12-17 Thread Peter Pearson
On Fri, 17 Dec 2021 09:25:03 +0100, ast wrote: [snip] > > but: > > li = [grp for k, grp in groupby("aahfffddnnb")] > list(li[0]) > > [] > > list(li[1]) > > [] > > It seems empty ... I don't understand why, this is > the first read of an iterator, it should provide its > data. Baffling.

Re: A problem with itertools.groupby

2021-12-17 Thread Chris Angelico
> list(li[1]) > > [] > > It seems empty ... I don't understand why, this is > the first read of an iterator, it should provide its > data. > https://docs.python.org/3/library/itertools.html#itertools.groupby Check the explanatory third paragraph :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: A problem with itertools.groupby

2021-12-17 Thread Antoon Pardon
but: li = [grp for k, grp in groupby("aahfffddnnb")] list(li[0]) [] list(li[1]) [] It seems empty ... I don't understand why, this is the first read of an iterator, it should provide its data. The group-iterators are connected. Each group-iterator is a wrapper around the original

A problem with itertools.groupby

2021-12-17 Thread ast
Python 3.9.9 Hello I have some troubles with groupby from itertools from itertools import groupby for k, grp in groupby("aahfffddnnb"): print(k, list(grp)) print(k, list(grp)) a ['a', 'a'] a [] h ['h'] h [] f ['f', 'f', 'f'] f [] d ['d', 'd'] d [] s ['s', 's', 's', 's'] s [] n

[issue33681] itertools.groupby() returned igroup is only callable once

2018-05-29 Thread Steven D'Aprano
Steven D'Aprano added the comment: This is standard behaviour for all iterators. Once you have iterated over them once, they are consumed, and iterating over them again returns nothing: py> it = iter("abc") py> print(list(it)) ['a', 'b', 'c'] py> print(list(it)) [] -- nosy:

[issue33681] itertools.groupby() returned igroup is only callable once

2018-05-29 Thread Med Nezar BELLAZRAK
New submission from Med Nezar BELLAZRAK : Hello, So i discovered a small unusual behavior (tracking it down was time-consuming) when using itertools.groupby(), i have checked the documentation and it states that: "The returned group is itself an iterator that shares the underlying ite

[issue32709] the iterable for itertools.groupby must be sorted

2018-01-29 Thread Stéphane Wirtel
Stéphane Wirtel added the comment: I am going to close my issue because with your use case, this issue makes no sense. -- stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue32709] the iterable for itertools.groupby must be sorted

2018-01-29 Thread Stéphane Wirtel
Stéphane Wirtel <steph...@wirtel.be> added the comment: good catch, I only use itertools.groupby when I work for a collection. -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python

[issue32709] the iterable for itertools.groupby must be sorted

2018-01-29 Thread Cheryl Sabella
string, but keep the ordering, such as: 'abbddd' into '5a6b4c4a3d' and itertools.groupby works very nicely for that. -- nosy: +csabella ___ Python tracker <rep...@bugs.python.org> <https://bugs.python

[issue32709] the iterable for itertools.groupby must be sorted

2018-01-29 Thread Stéphane Wirtel
Change by Stéphane Wirtel : -- keywords: +patch pull_requests: +5259 stage: -> patch review ___ Python tracker ___

[issue32709] the iterable for itertools.groupby must be sorted

2018-01-29 Thread Stéphane Wirtel
New submission from Stéphane Wirtel <steph...@wirtel.be>: The documentation of itertools.groupby indicates that generally, the iterable needs to be sorted. In fact, this iterable MUST be sorted. -- assignee: docs@python components: Documentation messages: 35 nosy: docs@

[issue30347] itertools.groupby() can fail a C assert()

2017-09-26 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue30347] itertools.groupby() can fail a C assert()

2017-09-26 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: New changeset d0b9dc33676bdad217d5074954c1b37d4ca54a10 by Serhiy Storchaka in branch '2.7': [2.7] bpo-30347: Stop crashes when concurrently iterate over itertools.groupby() iterators. (GH-1557). (#3772) https://github.com/python/cpython/commit

[issue30347] itertools.groupby() can fail a C assert()

2017-09-26 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- pull_requests: +3759 ___ Python tracker ___

[issue30347] itertools.groupby() can fail a C assert()

2017-09-26 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: New changeset 69b2dc8637ba924d78f9869be592c5a545510f10 by Serhiy Storchaka (Miss Islington (bot)) in branch '3.6': [3.6] bpo-30347: Stop crashes when concurrently iterate over itertools.groupby() iterators. (GH-1557) (#3770) https://github.com/python

[issue30347] itertools.groupby() can fail a C assert()

2017-09-26 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: New changeset c740e4fe8a9bc5815dc18c38d7f7600b128c3c51 by Serhiy Storchaka in branch 'master': bpo-30347: Stop crashes when concurrently iterate over itertools.groupby() iterators. (#1557) https://github.com/python/cpython/commit

[issue30347] itertools.groupby() can fail a C assert()

2017-09-26 Thread Roundup Robot
Changes by Roundup Robot : -- keywords: +patch pull_requests: +3757 ___ Python tracker ___

[issue30347] itertools.groupby() can fail a C assert()

2017-09-25 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Hmm, the sole issue30346 is not enough for fixing this crash. I don't know if there is a simpler fix based on issue30346, but since PR 1557 removes the code duplication I'm going to merge it in any case. -- ___

[issue30347] itertools.groupby() can fail a C assert()

2017-09-25 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- versions: -Python 3.5 ___ Python tracker ___

[issue30347] itertools.groupby() can fail a C assert()

2017-09-25 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- assignee: rhettinger -> serhiy.storchaka ___ Python tracker ___

[issue27385] itertools.groupby has misleading doc string

2017-09-25 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: +Python 3.7 -Python 2.7, Python 3.5 ___ Python tracker

[issue27385] itertools.groupby has misleading doc string

2017-09-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset e2a30cd35b95dad55aea10347655f246348d1951 by Raymond Hettinger (Miss Islington (bot)) in branch '3.6': [3.6] bpo-27385: Clarify docstring for groupby() (GH-3738) (#3744)

[issue27385] itertools.groupby has misleading doc string

2017-09-25 Thread Roundup Robot
Changes by Roundup Robot : -- pull_requests: +3731 ___ Python tracker ___

[issue27385] itertools.groupby has misleading doc string

2017-09-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 49392c63a243052c8013bef80d35202bb6d7c404 by Raymond Hettinger in branch 'master': bpo-27385: Clarify docstring for groupby() (#3738) https://github.com/python/cpython/commit/49392c63a243052c8013bef80d35202bb6d7c404 --

[issue27385] itertools.groupby has misleading doc string

2017-09-24 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- pull_requests: +3724 ___ Python tracker ___

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-09-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Added the patch for PR 1568 against the current master just for history. -- Added file: https://bugs.python.org/file47167/groupby-invalid.diff ___ Python tracker

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-09-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Thank you for your review and explanations Raymond. This makes sense to me. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-09-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: New changeset c247caf33f6e6000d828db4762d1cb12edf3cd57 by Serhiy Storchaka in branch 'master': bpo-30346: An iterator produced by the itertools.groupby() iterator (#1569) https://github.com/python/cpython/commit/c247caf33f6e6000d828db4762d1cb12edf3cd57

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-09-24 Thread Raymond Hettinger
Raymond Hettinger added the comment: Go ahead with PR 1569 to exhaust the inner iterator when the outer iterator advances. Rationale: The OP expected the inner iterator to be exhausted. That is also what the PyPy team originally implemented and it is what I would have expected. Also, there

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-09-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Ping. Can you make your decision Raymond? This issue is a stopper for issue30347 which fixes a crash. I don't want to merge the fix for issue30347 until this issue be solved, because both proposed PRs solve issue30347 too, and I don't want to make unneeded

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-29 Thread Raymond Hettinger
Raymond Hettinger added the comment: I've looked at the patches but am still thinking about what I prefer before committing to a re-design. Please give it a little time. There is zero urgency here (nothing is broken, no user complaints, etc). I have a bunch of other stuff on my plate for

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-28 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Raymond, could you please look at these patches? Both are small. What do you prefer? -- ___ Python tracker ___

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-13 Thread Tim Peters
Tim Peters added the comment: Users certainly have been fooled by this, although "unpacking" is a red herring. I've been burned by it, and I've seen StackOverflow puzzles related to the same thing. I think this is the heart of it: given a finite iterable I, it usually makes no semantic

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: PR 1568 and PR 1569 are two subvariants of #1. PR 1568 makes an inner iterator invalid and raising RuntimeError when used. PR 1569 makes an inner iterator exhausted. -- stage: -> patch review ___ Python tracker

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-13 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- pull_requests: +1664 ___ Python tracker ___ ___

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-13 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- pull_requests: +1663 ___ Python tracker ___ ___

[issue30347] itertools.groupby() can fail a C assert()

2017-05-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: At first glance, the suggested PR looks fine. Unless there is a rush, I would like to hold-off spend more time thinking about Issue 30346 before moving forward with this one. -- ___ Python tracker

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: > If I was to submit this as a PR, ... Please don't jump to writing code yet. We need to decide what should be done first. I'm not really excited about making a change at all. No users seem to have ever been affected by this. The CPython code matches

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-12 Thread Matthew Gilson
Matthew Gilson added the comment: Tracking which group the grouper _should_ be on using an incrementing integer seems to work pretty well. In additional to the tests in `test_itertools.py`, I've gotten the following tests to pass: class TestGroupBy(unittest.TestCase): def

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I agree and prefer #1. This will save users from incorrect using and us from reports about odd behavior. The implementation is simple. The groupby object generates an unique identifier when creates a new grouper. This may be a sequential integer, just

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: I have no interest in #2. Itertools are all about *not* storing data in memory unless that is an intrinsic requirement for the operation (tee() and cycle() for example). Also, I would like any changes to be minimal and have the lowest possible risk of

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Here is a Python implementation of the idea #2: from itertools import tee def groupby(iterable, key=None): if key is None: key = lambda x: x def grouper(currvalue, it, tgtkey): yield currvalue for currvalue in it:

[issue30347] itertools.groupby() can fail a C assert()

2017-05-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: PR 1557 implements the simplest fix -- remove the assert and use Py_XSETREF() instead of simple assignment. Since the resulting code in _grouper_next() is identical to the code in groupby_next(), it was shared between these two functions. -- stage:

[issue30347] itertools.groupby() can fail a C assert()

2017-05-12 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- pull_requests: +1653 ___ Python tracker ___ ___

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Does it make sense using a grouper after advancing the groupby iterator? Currently it is possible by accident: >>> from itertools import groupby, count >>> it = groupby(count(), lambda i: (i//10)%2) >>> _, even = next(it) >>> _, odd = next(it) >>>

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-12 Thread Matthew Gilson
Matthew Gilson added the comment: Oops. You don't need to pass `self.currvalue` to `_grouper`. I didn't end up using it in there... -- ___ Python tracker

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-12 Thread Matthew Gilson
Matthew Gilson added the comment: I think that works to solve the problem that I pointed out. In my stack overflow question (http://stackoverflow.com/a/43926058/748858) it has been pointed out that there are other opportunities for weirdness here. Specifically, if if I skip processing 2

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: I suppose that when the input iterator is exhausted, we could poison the currkey to make the subordinate iterator ends as well: def __next__(self): while self.currkey == self.tgtkey: try: self.currvalue =

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-11 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- priority: normal -> low ___ Python tracker ___

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-11 Thread Raymond Hettinger
Raymond Hettinger added the comment: FYI, the CPython behavior matches the pure python implementation show in the docs: Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "copyright", "credits" or "license()" for more

[issue30347] itertools.groupby() can fail a C assert()

2017-05-11 Thread Raymond Hettinger
Raymond Hettinger added the comment: Do you have a suggested fix? -- ___ Python tracker ___ ___

[issue30347] itertools.groupby() can fail a C assert()

2017-05-11 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- assignee: -> rhettinger components: +Extension Modules -Interpreter Core nosy: +rhettinger, serhiy.storchaka stage: -> needs patch versions: +Python 3.5, Python 3.6 ___ Python tracker

[issue30347] itertools.groupby() can fail a C assert()

2017-05-11 Thread Armin Rigo
groupby(range(10), f): print(list(b)) With current trunk we get: python: ./Modules/itertoolsmodule.c:303: _grouper_next: Assertion `gbo->currkey == NULL' failed. -- components: Interpreter Core messages: 293517 nosy: arigo priority: normal severity: normal status: open title: itertools

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-11 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- assignee: -> rhettinger nosy: +rhettinger ___ Python tracker ___

[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-05-11 Thread Matt Gilson
New submission from Matt Gilson: There is some odd behavior when unpacking the groups from an itertools.groupby result. For example: from itertools import groupby from operator import itemgetter inputs = ((x > 5, x) for x in range(10)) (_, a), (_, b) = groupby(inputs,

[issue27385] itertools.groupby has misleading doc string

2016-06-28 Thread Raymond Hettinger
Changes by Raymond Hettinger : Added file: http://bugs.python.org/file43571/groupbydoc.diff ___ Python tracker ___

[issue27385] itertools.groupby has misleading doc string

2016-06-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: That's okay. I'm taking care of both in this issue. -- ___ Python tracker ___

[issue27385] itertools.groupby has misleading doc string

2016-06-28 Thread R. David Murray
R. David Murray added the comment: Please open a separate issue for that problem. -- nosy: +r.david.murray ___ Python tracker ___

[issue27385] itertools.groupby has misleading doc string

2016-06-28 Thread Josh Rosenberg
Josh Rosenberg added the comment: While you're fixing, the docstring should say "groupby(iterable, key=None)", not "groupby(iterable[, keyfunc])"; the functions accepts the key function by name, and the name is key, not keyfunc. And it can be passed explicitly as None (equivalent to not

[issue27385] itertools.groupby has misleading doc string

2016-06-24 Thread Raymond Hettinger
Raymond Hettinger added the comment: The patch is fine. -- assignee: docs@python -> rhettinger priority: normal -> low ___ Python tracker ___

[issue27385] itertools.groupby has misleading doc string

2016-06-24 Thread Ned Deily
Changes by Ned Deily : -- nosy: +rhettinger stage: -> patch review versions: -Python 3.2, Python 3.3, Python 3.4 ___ Python tracker

[issue27385] itertools.groupby has misleading doc string

2016-06-24 Thread Grant Mathews
New submission from Grant Mathews: The itertools.groupby function is generally well-documented, but the fact that it only groups consecutive occurrences of keys is not mentioned in the doc string, which is where that information is most needed. -- assignee: docs@python components

[issue21771] name of 2nd parameter to itertools.groupby()

2014-06-15 Thread Uwe Kleine-König
New submission from Uwe Kleine-König: The name of the 2nd parameter to itertools.groupby() is documented inconsitently. Sometimes it's key, sometimes keyfunc. The code actually uses key, so I adapted all occurences I found to key. from itertools import groupby groupby.__doc__ 'groupby

[issue21771] name of 2nd parameter to itertools.groupby()

2014-06-15 Thread Ned Deily
Changes by Ned Deily n...@acm.org: -- nosy: +rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21771 ___ ___ Python-bugs-list mailing list

[issue21771] name of 2nd parameter to itertools.groupby()

2014-06-15 Thread Raymond Hettinger
Raymond Hettinger added the comment: There is a bit an inconsistency but it is more helpful than harmful most of the time. The glossary defines a key-function which is used in a number of places such such as sorted(), min(), nsmallest() and others. In all those cases, the parameter for the

[issue18245] In itertools.groupby() make data plural

2013-06-17 Thread py.user
: In itertools.groupby() make data plural versions: Python 3.3, Python 3.4 Added file: http://bugs.python.org/file30624/issue.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18245

[issue18245] In itertools.groupby() make data plural

2013-06-17 Thread Ned Batchelder
Ned Batchelder added the comment: Please don't make this change. Data is used as a singular collective noun, especially in software contexts. Data as a plural noun sounds archaic, or at best, scientific. -- nosy: +nedbat ___ Python tracker

[issue18245] In itertools.groupby() make data plural

2013-06-17 Thread R. David Murray
R. David Murray added the comment: Yes, the way it is now is normal written english, regardless of what any older official stylebooks may say :) -- nosy: +r.david.murray resolution: - invalid stage: - committed/rejected status: open - closed type: - behavior

[issue18245] In itertools.groupby() make data plural

2013-06-17 Thread Mark Dickinson
Mark Dickinson added the comment: In any case, the patch only gives half of the correction. The corrected test would have to be if *those* data are needed later rather than if that data are needed later. -- nosy: +mark.dickinson ___ Python tracker

[issue18245] In itertools.groupby() make data plural

2013-06-17 Thread Mark Dickinson
Mark Dickinson added the comment: Bah. s/test/text. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18245 ___ ___ Python-bugs-list mailing list

Re: itertools.groupby

2013-04-22 Thread Wolfgang Maier
Jason Friedman jsf80238 at gmail.com writes: Thank you for the responses!  Not sure yet which one I will pick. Hi again, I was working a bit on my own solution and on the one from Steven/Joshua, and maybe that helps you deciding: def separate_on(iterable, separator): # based on groupby

Re: itertools.groupby

2013-04-22 Thread Neil Cerutti
On 2013-04-20, Jason Friedman jsf80...@gmail.com wrote: I have a file such as: $ cat my_data Starting a new group a b c Starting a new group 1 2 3 4 Starting a new group X Y Z Starting a new group I am wanting a list of lists: ['a', 'b', 'c'] ['1', '2', '3', '4'] ['X', 'Y',

Re: itertools.groupby

2013-04-22 Thread Oscar Benjamin
On 22 April 2013 15:24, Neil Cerutti ne...@norwich.edu wrote: Hrmmm, hoomm. Nobody cares for slicing any more. def headered_groups(lst, header): b = lst.index(header) + 1 while True: try: e = lst.index(header, b) except ValueError: yield

Re: itertools.groupby

2013-04-22 Thread Neil Cerutti
On 2013-04-22, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 22 April 2013 15:24, Neil Cerutti ne...@norwich.edu wrote: Hrmmm, hoomm. Nobody cares for slicing any more. def headered_groups(lst, header): b = lst.index(header) + 1 while True: try: e =

Re: itertools.groupby

2013-04-22 Thread Chris Angelico
On Tue, Apr 23, 2013 at 12:49 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: Iterators are typically preferred over list slicing for sequential text file access since you can avoid loading the whole file at once. This means that you can process a large file while only using a constant

Re: itertools.groupby

2013-04-21 Thread Peter Otten
) as lines: stripped_lines = (line.strip() for line in lines) for header, group in itertools.groupby(stripped_lines, key=is_header): if not header: print(list(group)) And here's a refactoring for your initial code. The main point is the use of nonlocal instead of global

Re: itertools.groupby

2013-04-21 Thread Jason Friedman
#!/usr/bin/python3 from itertools import groupby def get_lines_from_file(file_name): with open(file_name) as reader: for line in reader.readlines(): yield(line.strip()) counter = 0 def key_func(x): if x.startswith(Starting a new group): global

Re: itertools.groupby

2013-04-21 Thread Joshua Landau
On 21 April 2013 01:13, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I wouldn't use groupby. It's a hammer, not every grouping job is a nail. Instead, use a simple accumulator: def group(lines): accum = [] for line in lines: line = line.strip() if

itertools.groupby

2013-04-20 Thread Jason Friedman
I have a file such as: $ cat my_data Starting a new group a b c Starting a new group 1 2 3 4 Starting a new group X Y Z Starting a new group I am wanting a list of lists: ['a', 'b', 'c'] ['1', '2', '3', '4'] ['X', 'Y', 'Z'] [] I wrote this:

Re: itertools.groupby

2013-04-20 Thread Ned Batchelder
On 4/20/2013 1:09 PM, Jason Friedman wrote: I have a file such as: $ cat my_data Starting a new group a b c Starting a new group 1 2 3 4 Starting a new group X Y Z Starting a new group I am wanting a list of lists: ['a', 'b', 'c'] ['1', '2', '3', '4'] ['X', 'Y', 'Z'] [] I wrote this:

Re: itertools.groupby

2013-04-20 Thread Wolfgang Maier
Jason Friedman jsf80238 at gmail.com writes: I have a file such as: $ cat my_data  Starting a new group a b c Starting a new group 1 2 3 4 Starting a new group X Y Z Starting a new group I am wanting a list of lists: ['a', 'b', 'c'] ['1', '2', '3', '4'] ['X',

Re: itertools.groupby

2013-04-20 Thread Steven D'Aprano
On Sat, 20 Apr 2013 11:09:42 -0600, Jason Friedman wrote: I have a file such as: $ cat my_data Starting a new group a b c Starting a new group 1 2 3 4 Starting a new group X Y Z Starting a new group I am wanting a list of lists: ['a', 'b', 'c'] ['1', '2', '3', '4'] ['X',

[issue14828] itertools.groupby not working as expected

2012-05-16 Thread Jiba
New submission from Jiba jibal...@free.fr: In some situation, itertools.groupby fails to group the objects, and produces several groups with the same key. For example, the following code : from itertools import * class P(object): def __init__(self, key): self.key = key p1 = P(1) p2

[issue14828] itertools.groupby not working as expected

2012-05-16 Thread Petri Lehtinen
Petri Lehtinen pe...@digip.org added the comment: groupby() changes the group when the key changes in the input it iterates. If you want to have p1 and p3 to go to the same group, you need to sort the input by P.key first. This is clearly documented, too: The operation of groupby() is

[issue14828] itertools.groupby not working as expected

2012-05-16 Thread Jiba
Jiba jibal...@free.fr added the comment: Ok, I understand. However, in my initial problem, the sequence passed to groupby was a set, e.g. (modifying my previous example) : groupby(set([p1, p2, p3]), lambda p: p.key) If I understand well how groupby() works, the result of a groupby

[issue14828] itertools.groupby not working as expected

2012-05-16 Thread Petri Lehtinen
Petri Lehtinen pe...@digip.org added the comment: You're right, the result over a set would be unpredictable. The point of the itertools module is to be able to a) cope with massive amounts of data and b) be a set of tools instead of complete solutions for all problems. Because of both of the

Re: itertools.groupby usage to get structured data

2011-02-07 Thread nn
with variable lists of 2) and 3) i.e. having also 'g3' as grouping element so the 'g2' dicts could also have their own subgroup and be even more nested then. I was trying something with itertools.groupby and updating nested dicts, but as i was writing the code it started to feel too verbose to me

Re: itertools.groupby usage to get structured data

2011-02-05 Thread Slafs
of grouping with variable lists of 2) and 3) i.e. having also 'g3' as grouping element so the 'g2' dicts could also have their own subgroup and be even more nested then. I was trying something with itertools.groupby and updating nested dicts, but as i was writing the code it started

Re: itertools.groupby usage to get structured data

2011-02-05 Thread Peter Otten
have their own subgroup and be even more nested then. I was trying something with itertools.groupby and updating nested dicts, but as i was writing the code it started to feel too verbose to me :/ Do You have any hints maybe? because i'm kind of stucked :/ Regards Sławek Not super

itertools.groupby usage to get structured data

2011-02-04 Thread Slafs
something with itertools.groupby and updating nested dicts, but as i was writing the code it started to feel too verbose to me :/ Do You have any hints maybe? because i'm kind of stucked :/ Regards Sławek -- http://mail.python.org/mailman/listinfo/python-list

Re: itertools.groupby usage to get structured data

2011-02-04 Thread Steven D'Aprano
of grouping with variable lists of 2) and 3) i.e. having also 'g3' as grouping element so the 'g2' dicts could also have their own subgroup and be even more nested then. I was trying something with itertools.groupby and updating nested dicts, but as i was writing the code it started to feel too

Re: itertools.groupby usage to get structured data

2011-02-04 Thread Paul Rubin
'g3' as grouping element so the 'g2' dicts could also have their own subgroup and be even more nested then. I was trying something with itertools.groupby and updating nested dicts, but as i was writing the code it started to feel too verbose to me :/ Do You have any hints maybe? because i'm

Re: bug with itertools.groupby?

2009-10-07 Thread Paul McGuire
On Oct 6, 6:06 pm, Kitlbast vlad.shevche...@gmail.com wrote: grouped acc:  61 grouped acc:  64 grouped acc:  61 am I doing something wrong? sort first, then groupby. -- http://mail.python.org/mailman/listinfo/python-list

bug with itertools.groupby?

2009-10-06 Thread Kitlbast
Hi there, the code below on Python 2.5.2: from itertools import groupby info_list = [ {'profile': 'http://somesite.com/profile1', 'account': 61L}, {'profile': 'http://somesite.com/profile2', 'account': 64L}, {'profile': 'http://somesite.com/profile3', 'account': 61L}, ]

Re: bug with itertools.groupby?

2009-10-06 Thread Diez B. Roggisch
#itertools.groupby Generally, the iterable needs to already be sorted on the same key function. Diez -- http://mail.python.org/mailman/listinfo/python-list

Re: bug with itertools.groupby?

2009-10-06 Thread Rhodri James
On Wed, 07 Oct 2009 00:06:43 +0100, Kitlbast vlad.shevche...@gmail.com wrote: Hi there, the code below on Python 2.5.2: from itertools import groupby info_list = [ {'profile': 'http://somesite.com/profile1', 'account': 61L}, {'profile': 'http://somesite.com/profile2', 'account':

Re: bug with itertools.groupby?

2009-10-06 Thread Kitlbast
3 times faster then itertools.groupby for my example (for tests I extend number of profiles) -- http://mail.python.org/mailman/listinfo/python-list

Re: bug with itertools.groupby?

2009-10-06 Thread Raymond Hettinger
On Oct 6, 4:06 pm, Kitlbast vlad.shevche...@gmail.com wrote: Hi there, the code below on Python 2.5.2: from itertools import groupby info_list = [     {'profile': 'http://somesite.com/profile1', 'account': 61L},     {'profile': 'http://somesite.com/profile2', 'account': 64L},    

[issue2246] itertools.groupby() leaks memory with circular reference

2008-10-20 Thread Martin v. Löwis
Changes by Martin v. Löwis [EMAIL PROTECTED]: -- status: closed - open ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue2246 ___ ___ Python-bugs-list

[issue2246] itertools.groupby() leaks memory with circular reference

2008-10-20 Thread Martin v. Löwis
Martin v. Löwis [EMAIL PROTECTED] added the comment: Already backported in r61287. -- status: open - closed ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue2246 ___

  1   2   >