Issue 1322308: itemgetter built-in? - Python tracker (original) (raw)

Created on 2005-10-10 09:56 by capnstabn, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg54626 - (view) Author: capnSTABN (capnstabn) Date: 2005-10-10 09:56
uhm... operator.itemgetter() is useful and all, but fairly retarded looking for how simple it is basically what i am wrestling with at the moment is doing some regular expressions without completely ganking the crap out of the code to make it work, since every freakin thing in re returns None all over the bloody place like regular expressions were hitting a ragging pinata with a chainsaw after a LOT of muckymuck, basically six hours straight, the simplest non-conditional form i could come up with was this: http://42.vg/81691</a> http://42.vg/81691 any comments would be leet!
msg54627 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-10-10 16:57
Logged In: YES user_id=1188172 Please tell us what your request for enhancement is or I'm going to close this as Invalid. Sorry I'm not showing more respect for your writing abilities :-), but if you want to show code around, do it on comp.lang.python please.
msg54628 - (view) Author: capnSTABN (capnstabn) Date: 2005-10-11 09:17
Logged In: YES user_id=1126596 my request for enhancement is either a built-in version of operation.itemgetter() or an alteration of the behavior of re matches, i'm assuming the matter is up for debate so i wasn't being specific. this issue has nothing to do with showing code and i find your followup to be completely off topic!
msg54629 - (view) Author: capnSTABN (capnstabn) Date: 2005-10-11 09:33
Logged In: YES user_id=1126596 ok to be more specific, as maybe that will help, line 17 in the code: for type, string_ in (filter(itemgetter(1), match.groupdict ().iteritems())): is about as implicit as pulling a tooth to remove a strand of celery the problem is that when using a single expansive recursive regular expression (which can translate an entire page of HTML like in any WikiWiki system in microseconds) that the amount of recursive calls because of all of the Nones flying around gets ludicrous a bit of a glimpse of a considerably more complex example: http://generic-host.us/~kevin/display_renderer.png please bear in mind that example is from 1999 or so
msg54630 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-11-14 12:19
Logged In: YES user_id=80475 The use case is common enough to warrant further exploration. Essentially what is being requested is a straight-forward way to get a group dictionary that only includes matching groups. Two approaches come to mind. 1. Add a module constant, EXCLUDE, that when used as the default value causes non-matching groups to be excluded from the group dictionary: d=mo.groupdict(re.EXCLUDE) 2. Create a new flag, N or NODEFAULT or (?N), indicating that match objects should only include matching groups and not create default entries for non-matches: d=match('(?\w+)|(?\d+)', s, NODEFAULT).groupdict() FWIW, am not sympathetic to the OP's code fragment not being explicit. That is what happens when trying too hard to avoid using an if-statement. The fragment is much clearer without filtering: for type, string_ in mo.groupdict().iteritems(): if string_ is not None: . . .
msg54631 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-03-30 07:20
None of the links provided work anymore, and I have no idea what is being proposed (save for Raymond's comment). If the goal is to clarify the code snippet supplied by the OP, I agree with Raymond: learn to use "if" statements. Closing as "invalid".
History
Date User Action Args
2022-04-11 14:56:13 admin set github: 42463
2005-10-10 09:56:02 capnstabn create