[Tutor] Selecting first matching element from a list
Noufal Ibrahim
noufal at nibrahim.net.in
Wed Jan 14 11:36:54 CET 2009
bob gailer wrote:
>
> 2) "looks bad" and "is ugly" are emotional responses. What are you
> feeling and wanting when you say those things?
It's hard for me to qualify really but my general idea of list
comprehensions is that they transform and filter lists creating other lists.
For instance, I'd call this
if key in foo:
return foo[key]
else:
return 'unknown'
'ugly' when compared to
return foo.get(key,'unknown')
I guess I'm looking for the idiomatic way of performing such an
operation. My gut feel tells me that the zeroth element of a list
comprehension is not the right way to go but I wanted
confirmation/rebuttal.
Peace.
--
~noufal
http://nibrahim.net.in/
More information about the Tutor
mailing list