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
"
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
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
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 (
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
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
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
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
>> 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
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
> 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
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
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
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
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,
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
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
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
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
19 matches
Mail list logo