Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: Inline Conditionals?

Reply
Thread Tools

RE: Inline Conditionals?

 
 
Robert Brewer
Guest
Posts: n/a
 
      08-26-2004
Alex Martelli wrote:
> Antoon Pardon <> wrote:
> ...
> > When using list comprehension not having a ternary operator can be
> > a PITA. It is of course possible I miss something but how am I
> > supposed to do the following:
> >
> > [ x.property ? foo(x) : bar(x) for x in Somelist ]

>
> If you HAVE to use an LC by doctor's order, the above effect might be
> obtained by coding something like:
>
> [ (bar,foo)[bool(x.property)](x) for x in Somelist ]
>
> If your physician should relent and let you code normal
> Python, though,
>
> aux = []
> for x in Somelist:
> if x.property:
> aux.append(foo(x))
> else
> aux.append(foo(x))
>
> would be vastly more readable; "sparse is better than dense"
> and any LC
> is far too dense to be Pythonic here.


Case in point: it makes it *vastly* easier to see the typo. What
happened to bar()?

But you planned that so someone else could deliver the punch line,
didn't you?


Robert Brewer
MIS
Amor Ministries

 
Reply With Quote
 
 
 
 
Alex Martelli
Guest
Posts: n/a
 
      08-26-2004
Robert Brewer <> wrote:
...
> > aux = []
> > for x in Somelist:
> > if x.property:
> > aux.append(foo(x))
> > else
> > aux.append(foo(x))
> >
> > would be vastly more readable; "sparse is better than dense"
> > and any LC
> > is far too dense to be Pythonic here.

>
> Case in point: it makes it *vastly* easier to see the typo. What
> happened to bar()?


Closing hours...?


> But you planned that so someone else could deliver the punch line,
> didn't you?


Ahem, yes, why, sure!


Alex
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tool which expands implicitly inline inline functions tthunder@gmx.de C++ 3 06-16-2005 12:54 AM
To inline or not to inline? Alvin C++ 7 05-06-2005 03:04 PM
Function delcared inline but not defined inline Nish C Programming 4 10-08-2004 03:31 PM
External inline functions calling internal inline functions Daniel Vallstrom C Programming 2 11-21-2003 01:57 PM
inline or not to inline in C++ Abhi C++ 2 07-03-2003 12:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57