Newbie Questions: Swithing from Perl to Python
Geoff Gerrietts
geoff at gerrietts.net
Sun Oct 26 01:18:51 EDT 2003
Quoting Todd Stephens (huzzah at tampabay.rr.com):
>
> Thanks for the info. Knowing that the Python community prefers one
> correct way to do something, can you explain to me how this is
> different/incorrect? :
I think the only danger with your solution is that you're relying on
the implicit behavior in the coerce-dictionary-to-list. When you ask a
dictionary for its keys, it's a little clearer what you're after. In
your example, if I didn't know already that list(myD) returned a list
of the keys, I would hafta wonder: is it a list of keys? A list of
values? A list of (key, value) tuples? In other words, you're
sacrificing some readability.
I'm not sure if the mapping interface requires implementations to
return the keys in the event of a coerce-to-list. If it does, then
there's no other weakness. If it doesn't, you may also be sacrificing
some of this construct's portability.
--G.
--
Geoff Gerrietts <geoff at gerrietts dot net> http://www.gerrietts.net/
karma police arrest this man he speaks in maths -- Radiohead, "Karma Police"
More information about the Python-list
mailing list