if the else short form

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Wed Oct 6 19:23:28 EDT 2010


In message <i8i1h8$dcl$1 at news.eternal-september.org>, BartC wrote:

> I use this syntax where there are two possibilities chosen according to
> condition 'a':
> 
> (a | b | c)

Algol 68!

> x = ("One","Two","Three") [i-1]
> 
> While this works for i = 1,2,3, it goes funny for i=0,-1,-2, and generates
> an error for the rest ...

x = {1 : "One", 2 : "Two", 3 : "Three"}.get(i, "None Of The Above")



More information about the Python-list mailing list