*-unpacking (Re: Fun with fancy slicing)
Alex Martelli
aleax at aleax.it
Fri Oct 3 13:27:45 EDT 2003
David Eppstein wrote:
> In article <22cfb.159311$hE5.5365335 at news1.tin.it>,
> Alex Martelli <aleax at aleax.it> wrote:
>
>> David Eppstein wrote:
>>
>> >> In the mean time, it isn't too hard to write a function which does
>> >> this:
>> >>
>> >> def first_rest(x):
>> >> return x[0], x[1:]
>> >
>> > Shouldn't that be called cons?
>>
>> Hmmm, feels more like the 'reverse' of a cons to me -- takes a list
>> and gives me the car and cdr...
>
> Well, but it returns an object composed of a car and a cdr, which is
> exactly what a cons is...
Yeah, the psychological issue is no doubt with calling 'list' that
argument -- cons takes TWO separate arguments (and the SECOND one
is normally a list), while this is being discussed in the context
of UN-packing, AND takes a single argument to boot. While of course
it's true that "return this, that" returns a tuple, thinking of it
in terms of "returning multiple objects" is most natural when you're
planning to unpack that tuple before it's had time to look around...;-).
Alex
More information about the Python-list
mailing list