Looking for the best way to translate an idiom

Lie Ryan lie.1296 at gmail.com
Sun Dec 14 23:46:58 CET 2008


On Sun, 14 Dec 2008 09:51:03 -0800, Paul  Moore wrote:

> On 14 Dec, 16:22, Bruno Desthuilliers
> <bdesth.quelquech... at free.quelquepart.fr> wrote:
>> if you only want the first returned value, you can just apply a slice:
>>
>> def f():
>>     return 1,2,3
>>
>> a = f()[0] + 1
> 
> Hmm, true. I'm not sure it's any less ugly, though :-)
> 
>> FWIW, Python 2.6 has NamedTuple objects...
> 
> I know, but I want to target 2.5+ (I still have a number of systems
> running 2.5)
> 

Ah, that discounts python 3.0
Python 3.0 allows you to do this:

a, b, *c = range(5)

# a >> 0
# b >> 1
# c >> [2, 3, 4]

*a, b, c = range(5)
# a >> [0, 1, 2]
# b >> 3
# c >> 4

a, *b, c = range(5)
# a >> 0
# b >> [1, 2, 3]
# C >> 4




More information about the Python-list mailing list