Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Counting in binary is just like counting in decimal -- if you are all thumbs. -- Glaser and Way


devel / comp.lang.python / Re: Non-deterministic set ordering

SubjectAuthor
o Re: Non-deterministic set orderingDan Stromberg

1
Re: Non-deterministic set ordering

<mailman.421.1652670801.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18284&group=comp.lang.python#18284

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: drsali...@gmail.com (Dan Stromberg)
Newsgroups: comp.lang.python
Subject: Re: Non-deterministic set ordering
Date: Sun, 15 May 2022 20:13:07 -0700
Lines: 32
Message-ID: <mailman.421.1652670801.20749.python-list@python.org>
References: <d93aad1d-8586-b844-d3de-fa9648535244@btinternet.com>
<CAGGBd_p3SqB-GRBW+DdTY6++DmJ2qHfJtQUK1u2Y18CG3nWuEA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de TkRUT6A04K5d44X4UnZqvQ016aMne49vh2CC5Kv+VX1Q==
Return-Path: <drsalists@gmail.com>
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=gmail.com header.i=@gmail.com header.b=XJpVBs83;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.012
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '2022': 0.05; 'sun,': 0.07;
'cc:addr:python-list': 0.09; 'email addr:python.org>': 0.09;
'identical': 0.09; 'order,': 0.09; '"real"': 0.16; 'assuming':
0.16; 'cc:name:python': 0.16; 'from:addr:drsalists': 0.16;
'from:name:dan stromberg': 0.16; 'operations,': 0.16; 'order?':
0.16; 'received:209.85.217': 0.16; 'tasks.': 0.16; 'wrote:': 0.16;
'python': 0.16; 'cc:addr:python.org': 0.20; 'code': 0.23; 'list,':
0.24; 'cc:2**0': 0.25; 'anyone': 0.25; 'output': 0.28; 'email
addr:python.org&gt;': 0.28; 'program': 0.31; 'python-list': 0.32;
"wouldn't": 0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'running': 0.34; 'subject:skip:d 10': 0.35; 'following': 0.35;
'from:addr:gmail.com': 0.35; 'received:209.85': 0.37;
'received:209': 0.39; 'developers': 0.39; 'use': 0.39; 'explain':
0.40; 'something': 0.40; 'should': 0.40; 'operations': 0.68;
'repeatedly': 0.69; 'discover': 0.80; 'email name:&lt;python-
list': 0.84; 'ordering': 0.84; 'rob': 0.84; 'subject:Non': 0.84;
'\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0': 0.84; 'shocked': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=xefMHZnN9pFTZarC1/P1k+U8aaVrdy7O5sLBuY1JqXE=;
b=XJpVBs83qnr+H2y4xGiKRnIYy6hLyrDNZKXPCs6LZZF9c0mqrCD5byC0CN6tKqo/ng
fwIfrk0SJLWvRAjeRDKrG22bMGF3sOa4XGs4ocIBbpK3z+dMHHG+NKF58F3qFJ0N6hNv
XlEo4ZrFs17axRFUIgnihhoQzNj/c7cWqkI9xc6jeVQ6a2cPdSM3eBKIU5/LVJ3Pg9Mb
cf7Y3m1NC7thviaJqsxAYiA03a8mFtB+nsecx7pjLDeWRE49thpjNVRbtuYMGr821dIM
a4cz4R4UKyPbfIyDTWKzGtgg1p4IkW06Efk7gm0J2cYuDq3+7lidi+L5YXpV88qke2TH
X+fQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=xefMHZnN9pFTZarC1/P1k+U8aaVrdy7O5sLBuY1JqXE=;
b=x5+eSBOy317ZlUPgrs4vDR+N2NWlyX6szpJ1n77ROPDdibkENsCSqojOpeIWqjN90g
SIfbwGN6PQtAOPgSsfguRLTRQkYUytdg6TgXyZdE8aHszeQUZcK4qr3ckP1YF0L9eDkI
xXof8SAd16KdjTtL3gZ5KFHUDVV7q6MkrXBiRK9xE9APL5Y+wdrVBll0qfhtSC4gLH2R
NNivsEyvQhZO4Ag25OTy+ibQNIeg+UGcq0ArRgmORaVT9UhSI9Io3MGrf9ilzCQWNG7j
+gbS+FsyPDmVvx6dLWByhnccDBhZ+W+Gsl+PjGekBPNfjarPD3ENaNrqTiYzKU9QO/LZ
QE/A==
X-Gm-Message-State: AOAM531258vzsV+ybwxmozX6xjhWy1WuowVNTiU6PMwVZ0UvZS2uAFGH
PMwqgmAvNeX9x4j6c2/IRigDwBJVw7nMiryOSLARWeOPAUo=
X-Google-Smtp-Source: ABdhPJyrKyIt0ZSnMHOV6DBVou5dBagnyOOgP/vyJAetBZdh2q7r8JZh8lowJcvRHcPTJH8gioUBfhn6AdlOFztpH4M=
X-Received: by 2002:a05:6102:32c7:b0:335:7d41:23e4 with SMTP id
o7-20020a05610232c700b003357d4123e4mr4339544vss.67.1652670798566; Sun, 15 May
2022 20:13:18 -0700 (PDT)
In-Reply-To: <d93aad1d-8586-b844-d3de-fa9648535244@btinternet.com>
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <CAGGBd_p3SqB-GRBW+DdTY6++DmJ2qHfJtQUK1u2Y18CG3nWuEA@mail.gmail.com>
X-Mailman-Original-References: <d93aad1d-8586-b844-d3de-fa9648535244@btinternet.com>
 by: Dan Stromberg - Mon, 16 May 2022 03:13 UTC

On Sun, May 15, 2022 at 8:01 PM Rob Cliffe via Python-list <
python-list@python.org> wrote:

> I was shocked to discover that when repeatedly running the following
> program (condensed from a "real" program) under Python 3.8.3
>
> for p in { ('x','y'), ('y','x') }:
> print(p)
>
> the output was sometimes
>
> ('y', 'x')
> ('x', 'y')
>
> and sometimes
>
> ('x', 'y')
> ('y', 'x')
>
> Can anyone explain why running identical code should result in
> traversing a set in a different order?
>

Sets are defined as unordered so that they can be hashed internally to give
O(1) operations for many tasks.

It wouldn't be unreasonable for sets to use a fixed-by-arbitrary ordering
for a given group of set operations, but being unpredictable deters
developers from mistakenly assuming they are ordered.

If you need order, you should use a tuple, list, or something like
https://grantjenks.com/docs/sortedcontainers/sortedset.html

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor