[ python-Feature Requests-1322308 ] itemgetter built-in?
SourceForge.net
noreply at sourceforge.net
Mon Nov 14 13:19:52 CET 2005
Feature Requests item #1322308, was opened at 2005-10-10 04:56
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1322308&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: capnSTABN (capnstabn)
Assigned to: Nobody/Anonymous (nobody)
Summary: itemgetter built-in?
Initial Comment:
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:
<a href="http://42.vg/81691"
target="_new">http://42.vg/81691</a>
http://42.vg/81691
any comments would be leet!
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2005-11-14 07:19
Message:
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('(?<id>\w+)|(?<val>\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:
. . .
----------------------------------------------------------------------
Comment By: capnSTABN (capnstabn)
Date: 2005-10-11 04:33
Message:
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
----------------------------------------------------------------------
Comment By: capnSTABN (capnstabn)
Date: 2005-10-11 04:17
Message:
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!
----------------------------------------------------------------------
Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-10-10 11:57
Message:
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.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1322308&group_id=5470
More information about the Python-bugs-list
mailing list