Re: Multiple Assignment a = b = c

2016-02-16 Thread Terry Reedy
On 2/16/2016 7:46 AM, srinivas devaki wrote: Hi, a = b = c as an assignment doesn't return anything, i ruled out a = b = c as chained assignment, like a = (b = c) SO i thought, a = b = c is resolved as a, b = [c, c] https://docs.python.org/3/reference/simple_stmts.html#assignment-statements "

Re: Multiple Assignment a = b = c

2016-02-16 Thread srinivas devaki
On Tue, Feb 16, 2016 at 6:35 PM, Sven R. Kunze wrote: > > First, the rhs is evaluated. > Second, the lhs is evaluated from left to right. Great, I will remember these two lines :) On Tue, Feb 16, 2016 at 8:46 PM, Steven D'Aprano wrote: > _temp = c > a = _temp > b = _temp > del _temp > > > except

Re: Multiple Assignment a = b = c

2016-02-16 Thread Steven D'Aprano
On Tue, 16 Feb 2016 11:46 pm, srinivas devaki wrote: > Hi, > > a = b = c > > as an assignment doesn't return anything, i ruled out a = b = c as > chained assignment, like a = (b = c) > SO i thought, a = b = c is resolved as > a, b = [c, c] That is one way of thinking of it. A better way would b

Re: Multiple Assignment a = b = c

2016-02-16 Thread Sven R. Kunze
On 16.02.2016 14:05, Sven R. Kunze wrote: Hi Srinivas, I think the tuple assignment you showed basically nails it. First, the rhs is evaluated. Second, the lhs is evaluated from left to right. Completely wrong? Best, Sven As you mentioned swapping. The following two statements do the same (

Re: Multiple Assignment a = b = c

2016-02-16 Thread Sven R. Kunze
Hi Srinivas, On 16.02.2016 13:46, srinivas devaki wrote: Hi, a = b = c as an assignment doesn't return anything, i ruled out a = b = c as chained assignment, like a = (b = c) SO i thought, a = b = c is resolved as a, b = [c, c] at-least i fixed in my mind that every assignment like operation

Re: multiple assignment

2006-03-28 Thread bruno at modulix
Anand wrote: >>>Wouldn't it be nice to say >>>id, *tokens = line.split(',') >> >> >>id, tokens_str = line.split(',', 1) > > > But then you have to split tokens_str again. > > id, tokens_str = line.split(',', 1) > tokens = tokens_str.split(',') > > this is too verbose. > head_tail = lambda seq

Re: multiple assignment

2006-03-24 Thread Magnus Lycka
Anand wrote: > Suppose i have a big list and i want to take tke the first one and rest > of the list like car/cdr in lisp. > is there any easy way to do this in python? It seems like overkill to me to make the syntax more complex just to avoid writing a one-line function. def first_rest(seq): ret

Re: multiple assignment

2006-03-23 Thread Steven Bethard
Anand wrote: >>> Wouldn't it be nice to say >>> id, *tokens = line.split(',') >> >> id, tokens_str = line.split(',', 1) > > But then you have to split tokens_str again. > > id, tokens_str = line.split(',', 1) > tokens = tokens_str.split(',') Sorry, it wasn't clear that you needed the tokens from

Re: multiple assignment

2006-03-22 Thread Anand
>> Wouldn't it be nice to say >> id, *tokens = line.split(',') > > > id, tokens_str = line.split(',', 1) But then you have to split tokens_str again. id, tokens_str = line.split(',', 1) tokens = tokens_str.split(',') this is too verbose. anand -- http://mail.python.org/mailman/listinfo/python

Re: multiple assignment

2006-03-22 Thread Steven Bethard
Anand wrote: > Wouldn't it be nice to say > > id, *tokens = line.split(',') id, tokens_str = line.split(',', 1) STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: multiple assignment

2006-03-22 Thread Anand
> You're right, that would not be so far off. > But then, the following should be also supported: > > *x, y = a # x, y = a[:-1], y = a[-1] > x, *y, z = a # x, y, z = a[0], a[1:-1], a[-1] > > Of course, there can be only one variable with an asterisk. > (But note that in the situation of a function

Re: multiple assignment

2006-03-22 Thread Fredrik Lundh
Christoph Zwerschke wrote: > You're right, that would not be so far off. > But then, the following should be also supported: > > *x, y = a # x, y = a[:-1], y = a[-1] > x, *y, z = a # x, y, z = a[0], a[1:-1], a[-1] > > Of course, there can be only one variable with an asterisk. > (But note that in

Re: multiple assignment

2006-03-22 Thread Christoph Zwerschke
Anand schrieb: > Suppose i have a big list and i want to take tke the first one and rest > of the list like car/cdr in lisp. > is there any easy way to do this in python? > > Only way i know is > > a = range(10) > x, y = a[0], a[1:] You have so many higher-level ways to access and iterate throug

Re: Multiple assignment and the expression on the right side

2006-02-21 Thread Terry Hancock
On Tue, 21 Feb 2006 10:53:21 +0530 Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: > I read in "Python in a Nutshell" that when we have > multiple assignments > made on a single line, it is equivalent to have those many > simple assignments and that the right side is evaluated > once fo

Re: Multiple assignment and the expression on the right side

2006-02-21 Thread Alex Martelli
Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: ... > I think I got confused because of "Each time" in the sentence which > gives a feeling that it gets executed several times. Maybe, It could > have been just written, "When the statement gets executed, the right > hand side is evaluated once,

Re: Multiple assignment and the expression on the right side

2006-02-20 Thread Suresh Jeevanandam
Alex Martelli wrote: > Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: > >> Dear all, >> I read in "Python in a Nutshell" that when we have multiple assignments >> made on a single line, it is equivalent to have those many simple >> assignments and that the right side is evaluated once for ea

Re: Multiple assignment and the expression on the right side

2006-02-20 Thread Andrea Griffini
While I think that the paragraph is correct still there is IMO indeed the (low) risk of such a misunderstanding. The problem is that "the statement executes" can IMO easily be understood as "the statements execute" (especially if your background includes only languages where there's no multiple ass

Re: Multiple assignment and the expression on the right side

2006-02-20 Thread Alex Martelli
Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: > Dear all, > I read in "Python in a Nutshell" that when we have multiple assignments > made on a single line, it is equivalent to have those many simple > assignments and that the right side is evaluated once for each > assignment. [The wordin

Re: Multiple assignment and the expression on the right side

2006-02-20 Thread Robert Kern
Suresh Jeevanandam wrote: > Dear all, > I read in "Python in a Nutshell" that when we have multiple assignments > made on a single line, it is equivalent to have those many simple > assignments and that the right side is evaluated once for each > assignment. [The wordings are mine. I am no