Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #196986

Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Thomas Passin <list1@tompassin.net>
Newsgroups comp.lang.python
Subject Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
Date Fri, 8 Nov 2024 17:00:31 -0500
Lines 76
Message-ID <mailman.89.1731115813.4695.python-list@python.org> (permalink)
References <seven-20241106014329@ram.dialup.fu-berlin.de> <vgg5dn$ij48$1@solani.org> <050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green> <vgjoe9$2stii$2@dont-email.me> <vgjq77$aj8c$1@solani.org> <59a78893-d96a-4f5b-921f-5ad862449ca2@DancesWithMice.info> <5b6c9d39-2a1a-4554-8cd8-da123411eb81@tompassin.net>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de Rh8fsO/rGztXTR3AYkXq7Q2PyqU3NAS+4NInG7QzxMQQ==
Cancel-Lock sha1:hm8s8FksLn5fun0niLMdMXKsQxg= sha256:Huju9Y34CCt2qHpNxyyPn/vX50siqb0BAc94DXMALjA=
Return-Path <list1@tompassin.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
Authentication-Results mail.python.org; dkim=pass reason="2048-bit key; unprotected key" header.d=tompassin.net header.i=@tompassin.net header.b=En7T/88Q; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'this:': 0.03; 'python:': 0.05; 'adapt': 0.09; 'browser,': 0.09; 'expression': 0.09; 'pre': 0.09; 'python"': 0.09; 'question:': 0.09; 'shock': 0.09; 'subject:Python': 0.12; 'possible,': 0.15; 'alias': 0.16; 'applied:': 0.16; 'pythonic': 0.16; 'received:10.0.0': 0.16; 'received:100.112': 0.16; 'received:64.90': 0.16; 'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16; 'received:dreamhost.com': 0.16; 'wrote:': 0.16; 'python': 0.16; 'probably': 0.17; 'pm,': 0.19; 'to:addr:python-list': 0.20; 'languages': 0.22; 'code': 0.23; 'python,': 0.25; 'programming': 0.25; 'local': 0.27; '>>>': 0.28; 'header:User-Agent:1': 0.30; 'review,': 0.31; 'question': 0.32; 'driving': 0.32; 'python-list': 0.32; 'received:10.0': 0.32; 'received:mailchannels.net': 0.32; 'received:relay.mailchannels.net': 0.32; 'but': 0.32; 'header:In- Reply-To:1': 0.34; 'trying': 0.35; '"the': 0.35; 'fine': 0.35; 'submitted': 0.35; '...': 0.37; 'could': 0.37; 'way': 0.38; 'use': 0.39; 'received:100': 0.39; 'still': 0.40; 'define': 0.40; 'learn': 0.40; 'something': 0.40; 'should': 0.40; 'above': 0.62; 'to:': 0.62; 'your': 0.64; 'well': 0.65; 'header:Received:6': 0.67; 'received:64': 0.68; 'rules': 0.70; 'subject:List': 0.71; 'left': 0.83; '1);': 0.84; 'subject:Posting': 0.84; 'zen': 0.84; '\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0': 0.84; 'badly': 0.91
X-Sender-Id dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal i=1; s=arc-2022; d=mailchannels.net; t=1731103233; a=rsa-sha256; cv=none; b=336jk93q4RJCkUDMWg41QCC/gcLRzT42CPywz0JtQgnpmyI1fIv+alELOLYSpsxXCVjuGH Q8DEvAKr+zoILyjx2S8YaNAIdeJAaYg5GOPD8SLlXDAHx7zPRNEN/tWo1Tt/rElFWJI3c5 QJhJ8yUhnVpGoaug/c0ERI8fJyqdhdzuXbBiSYAhVdSDDC2ZMCaKHxLUkBThbiZFZLgYNR ycLhrrE5HDStkXyrRK+m4VArbFAyT3kQY4IrapHYvOOS2Npr4IIzm65f0WjQO0Zk2bq57z 7IIAaKUX8+bIAIL9sU2FTFhqWTe2uHpqlgv80PJcDf00nepGryWJKJ0ti1ZHTw==
ARC-Message-Signature i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1731103233; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=S8IcJ9ieTc0CHpnIz6rSM5/dqUXnbVlj4pEVUNYDia4=; b=NqZLdVagUuR0LOok/KZwjRbhihNyGCdgYeJuk7PWURtSPSCc0XEviaxcZw8y/w8qJ2nJfV AZIw6dVOf6PElAhqRlEW0q9cnn6B25YFl/t3ORNJ82qD8zxraVtBPhdnaxCi8QR00RtDgA MK1tib54xKMsjDq6Fnei2bcFOlAqHaE1DpOUVZywNd9ZZAEFuZs3emRAutlP3FvQ6FtwHf 86F9Mg0HLflTuSVc8plt4QX3JBkN9jXBYHa5i+3TV1D9lS4omyPg/Z1ktUG6v3obF6rNg6 fjUE06CoBMoNSKNzMdLdrgTBZ5SC6plqjUEuE+0zgKWJtNuVtJXqVBthsSNeQg==
ARC-Authentication-Results i=1; rspamd-56654dd69b-v7p4n; auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay Neutral
X-MailChannels-SenderId dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id dreamhost
X-Shade-Thread 4ef115826633fc1f_1731103233434_576023272
X-MC-Loop-Signature 1731103233434:202020567
X-MC-Ingress-Time 1731103233434
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net; s=dreamhost; t=1731103233; bh=S8IcJ9ieTc0CHpnIz6rSM5/dqUXnbVlj4pEVUNYDia4=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=En7T/88QpNxFOyjJfd4EvGSrQ+DL/8P2n72a8OxVve978hRB/90QLyIHYrqlNWcfj 6rGlJy64oe1JR1CL54d3WcembCjJc31EaeUrNxV06x8ERoIYKhm+kWUbwu8LSWq1Jx H5tkfdwh6s9BWzkEtRbFMbacqAiOM5HCt2e4IlocLfc4q4CMnZqtAcCt1My2TY8I5/ brBT/KO1Imlv2jgmT2J8hAE6ZUtMroGsy7HeQ8uZG2lznhGnP3aDwyFh1yYMSF49tw sv9+9GoSluAmmlnZ9FawEg1Mt2Yxy6Qz/uQUj2QMOlMMyw4NWTvM5/AAFuqDZ3a+VS 4vOxEqFx5h3Sg==
User-Agent Mozilla Thunderbird
Content-Language en-US
In-Reply-To <59a78893-d96a-4f5b-921f-5ad862449ca2@DancesWithMice.info>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.39
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <https://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <5b6c9d39-2a1a-4554-8cd8-da123411eb81@tompassin.net>
X-Mailman-Original-References <seven-20241106014329@ram.dialup.fu-berlin.de> <vgg5dn$ij48$1@solani.org> <050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green> <vgjoe9$2stii$2@dont-email.me> <vgjq77$aj8c$1@solani.org> <59a78893-d96a-4f5b-921f-5ad862449ca2@DancesWithMice.info>
Xref csiph.com comp.lang.python:196986

Show key headers only | View raw


On 11/8/2024 2:09 PM, dn via Python-list wrote:
> On 8/11/24 14:40, Mild Shock via Python-list wrote:
>> Well you can use your Browser, since
>> JavaScript understand post and pre increment:
> 
> Question: are we talking Python or JavaScript?
> 
> 
>> So we have x ++ equals in Python:
> 
> Trying to find a word-for-word translation serves as badly in computer- 
> programming languages as it does in human spoken-languages. Learn how to 
> adapt and embrace the differences...
> 
> 
>>      x + = 1
>>      x - 1
> 
> The above probably only 'works' (the way you expect) in the REPL.
> 
> 
>> But I don't know how to combine an
>> assignment and an expression into one
>> expession. In JavaScript one can use
> 
> Again!
> 
> "Everything should be made as simple as possible, but no simpler."
> 
> Check out "The Zen of Python" and PEP-0008 for Python idioms.
> 
> 
>> the comma:
>>
>>  > x = 5
>> 5
>>  > y = (x += 1, x - 1)
>> 5
>>  > x = 5
>> 5
>>  > y = (x += 1, x)
>> 6
>>
>> But in Python the comma would create a tuple.
> 
> Exactly, just as driving on the left side of the road will be fine in 
> some countries but cause a crash in others. Learn the local rules FIRST!
> 
> 
> The 'walrus operator' could be applied:
> 
>  >>> x = 5
>  >>> y = (x := x + 1); x
> 6
>  >>> x, y
> (6, 6)
> 
> However, if such were submitted for Code Review, unhappiness would result.
> 
> 
> Was the question re-phrased to: how to ... in Python, we'd end-up with 
> something more like this:
> 
>  >>> x = 5  # define
>  >>> x += 1  # increment
>  >>> y = x  # alias
>  >>> x, y
> (6, 6)

Or, still Pythonic but simpler:

 >>> x = 5
 >>> y = x = x + 1
 >>> x, y
(6, 6)

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-06 17:27 +0100
  Re: Two aces up Python's sleeve Annada Behera <annada@tilde.green> - 2024-11-07 12:55 +0530
    Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-07 15:04 +0100
      Re: Two aces up Python's sleeve Greg Ewing <greg.ewing@canterbury.ac.nz> - 2024-11-08 11:15 +1300
        Re: Two aces up Python's sleeve dn <PythonList@DancesWithMice.info> - 2024-11-08 13:07 +1300
        Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-08 01:25 +0100
          Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-08 01:29 +0100
            Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-08 01:47 +0100
    Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-08 01:10 +0000
      Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Mild Shock <janburse@fastmail.fm> - 2024-11-08 02:40 +0100
        Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) dn <PythonList@DancesWithMice.info> - 2024-11-09 08:09 +1300
          Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Mild Shock <janburse@fastmail.fm> - 2024-11-08 20:49 +0100
        Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Thomas Passin <list1@tompassin.net> - 2024-11-08 17:00 -0500

csiph-web