Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Save energy: Drive a smaller shell.


devel / comp.lang.python / Re: xor operator

SubjectAuthor
o Re: xor operatorDom Grigonis

1
Re: xor operator

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!paganini.bofh.team!2.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: dom.grig...@gmail.com (Dom Grigonis)
Newsgroups: comp.lang.python
Subject: Re: xor operator
Date: Wed, 15 Nov 2023 21:00:06 +0200
Lines: 89
Message-ID: <mailman.263.1700074811.3828.python-list@python.org>
References: <44FBD8A8-E092-40FF-BD56-467E6936AAE9@gmail.com>
<E04D5B2F-68AF-41C1-A160-A65BFA44202F@barrys-emacs.org>
<CABpSurBKGX4M-d9N4gYnDKwisYV+bUEYgabAfJdsQ+B-Zqk=Fg@mail.gmail.com>
<166AE5F3-3FF0-458D-9DA8-D6A7367122C4@gmail.com>
<20231115003415.mtertwoelhjme4aq@hjp.at>
<0E0F3061-A807-4471-9F85-1571259D0705@gmail.com>
<20231115171650.sgt5daojsun2cxrj@hjp.at>
<9E5DAA3E-5670-4056-A73C-4CF363217238@gmail.com>
<0A185341-8563-4E4E-B098-70772FFA9EFD@gmail.com>
Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\))
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de a/z6ZrmttUKB3r4gYCyEgA3TMQGP08sIRuhlRaC/wl6Q==
Cancel-Lock: sha1:lA+nkUwMuI5CP+PVC0SptZgVqHU= sha256:JU2NpyIs5cujfFM0vJMY1ly9mT5XE97sj+Rz7imVc8Y=
Return-Path: <dom.grigonis@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=ZkndzbVy;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'fairly':
0.05; 'e.g.': 0.07; 'loop': 0.07; 'received:mail-
ed1-x52b.google.com': 0.07; 'suggestion': 0.07; 'cc:addr:python-
list': 0.09; 'construct': 0.09; 'dev.': 0.09; 'obviously': 0.09;
'obviously,': 0.09; 'situation,': 0.09; '&gt;': 0.14;
'url:mailman': 0.15; '"creative': 0.16; '&lt;': 0.16; '+0200,':
0.16; '1,000,000': 0.16; '__/': 0.16; 'cc:name:python': 0.16;
'challenge!"': 0.16; 'each)': 0.16; 'hjp@hjp.at': 0.16; 'holzer':
0.16; 'lambda': 0.16; 'loops': 0.16; 'python\xe2\x80\x99s': 0.16;
'reality.': 0.16; 'received:apple': 0.16;
'received:smtpclient.apple': 0.16; 'stross,': 0.16; 'structure.':
0.16; 'url-ip:212.17.106/24': 0.16; 'url-ip:212.17/16': 0.16;
'url:hjp': 0.16; '|_|_)': 0.16; 'wrote:': 0.16; 'values': 0.17;
'message-id:@gmail.com': 0.18; 'cc:addr:python.org': 0.20; 'skip:_
10': 0.22; 'anything': 0.25; 'url-ip:188.166.95.178/32': 0.25;
'url-ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'cc:2**0':
0.25; 'url-ip:188.166/16': 0.25; 'seems': 0.26; '>>>': 0.28;
'sense': 0.28; 'email addr:python.org&gt;': 0.28; 'code,': 0.31;
'url-ip:188/8': 0.31; 'think': 0.32; 'question': 0.32; 'elements':
0.32; 'python-list': 0.32; 'but': 0.32; "i'm": 0.33; 'there':
0.33; '100': 0.33; 'someone': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'following': 0.35;
'from:addr:gmail.com': 0.35; 'count': 0.36; 'necessarily': 0.37;
"it's": 0.37; 'class': 0.37; 'hard': 0.37; 'least': 0.39; 'list':
0.39; 'use': 0.39; 'situation': 0.40; 'likely': 0.61; 'your':
0.64; 'back': 0.67; 'per': 0.68; 'url-ip:212/8': 0.69; 'too.':
0.70; 'performance': 0.71; 'deal': 0.73; 'choice': 0.76; '1.6':
0.84; 'dom': 0.84; 'email name:&lt;python-list': 0.84; 'ideally':
0.84; 'received:88': 0.84; 'truth': 0.86
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1700074809; x=1700679609; darn=python.org;
h=references:to:cc:in-reply-to:date:subject:mime-version:message-id
:from:from:to:cc:subject:date:message-id:reply-to;
bh=Bptit9gM98kI3anwJt/RW3XQ1Mpz6WmoVuWJWdlbO0g=;
b=ZkndzbVyo/+zC39LG8SLn8fqRanHNJgH5Ufk4LoT4TysWS7zafpyrtktsMz1qIqIGO
5gBQjTHShdQAzK4X2DCxXXE2shDPlZnJvToo46OdTqqWcOVDbiHdd7bu2uo5wkMMom/z
71O7OZwyivxHCImbm4umg5C95ncPnzvHQDM5DcaPoPRDdZoUPubmXLnwZiCSaeh919Jg
kZG0GNQco8E1hZZYp41a1OMeX8FzDVlsHCG3ORowi2UP5RbgpWpx2fwVM9CXrdsDztu1
0BsPdraJotH9EFIJd3xa6BkUHkShTks1uOFk330h6ATakkU5dcxjnHuCxMewJlfeX0BJ
eduQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1700074809; x=1700679609;
h=references:to:cc:in-reply-to:date:subject:mime-version:message-id
:from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=Bptit9gM98kI3anwJt/RW3XQ1Mpz6WmoVuWJWdlbO0g=;
b=T8QUP1GfjyKbqrM0FQmTneXStvMFeShmzeNme5/45pNKWyOzHsJNkOJCeTUaTVnXq6
BEsLlvzLW7FfSAXOnVSSM/maMPKB3zKfZcbY/6oB4BohiST16nu3Pvr5/wuHFiMp9bdg
/Wid14XdSyAPTZsVnOg5yZPUcKQoCXs5tvPS8xMaJjP4ZsQSmsUSD5YHyDgUSsy3wAC+
Ub0uw5iZt8G9DzRp+xf0xwS5vC0WaeyfxNvKI3FuWFU/BUf/cHYVKx2FpNeSRanbfF3v
LqqJmJm9lsv+IzKLRekHy+M5gA+GCEEvrmASzlXtxLXDb68zEHltcSl4krwlZQ2/K/pK
QkuQ==
X-Gm-Message-State: AOJu0YzSTrj3XhjHh1NJAO2MqhplBxTcmgv8LxBbH6uDPXk9aymJfgOq
gqkTISt6tVt3XGPmeVSmKWM=
X-Google-Smtp-Source: AGHT+IFAialRlSTC+bO7aG8oWy3XbdYUGfpt+ylkpUG/ZDTECIls7XNWDjwGc2+WxyEuOr8dnLG2CA==
X-Received: by 2002:aa7:c6d7:0:b0:543:57dd:503 with SMTP id
b23-20020aa7c6d7000000b0054357dd0503mr5904469eds.3.1700074808884;
Wed, 15 Nov 2023 11:00:08 -0800 (PST)
In-Reply-To: <9E5DAA3E-5670-4056-A73C-4CF363217238@gmail.com>
X-Mailer: Apple Mail (2.3654.120.0.1.15)
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: <0A185341-8563-4E4E-B098-70772FFA9EFD@gmail.com>
X-Mailman-Original-References: <44FBD8A8-E092-40FF-BD56-467E6936AAE9@gmail.com>
<E04D5B2F-68AF-41C1-A160-A65BFA44202F@barrys-emacs.org>
<CABpSurBKGX4M-d9N4gYnDKwisYV+bUEYgabAfJdsQ+B-Zqk=Fg@mail.gmail.com>
<166AE5F3-3FF0-458D-9DA8-D6A7367122C4@gmail.com>
<20231115003415.mtertwoelhjme4aq@hjp.at>
<0E0F3061-A807-4471-9F85-1571259D0705@gmail.com>
<20231115171650.sgt5daojsun2cxrj@hjp.at>
<9E5DAA3E-5670-4056-A73C-4CF363217238@gmail.com>
 by: Dom Grigonis - Wed, 15 Nov 2023 19:00 UTC

In case someone is actually going to execute the code, there is a bug:

`set` need to be wrapped in `len` for criteria args.

> On 15 Nov 2023, at 20:13, Dom Grigonis <dom.grigonis@gmail.com> wrote:
>
>
> The specific situation was related to truth values and following out of that my considerations regarding equivalent of all and any for counting `truths`.
>
> So one of the specific examples:
> class Publisher:
> def __init__(self):
> self.subscribers = dict()
>
> def subscribe(self, sub, criteria, agg=all):
> self.subscribers[sub] = (criteria, agg)
>
> def publish(self, msg):
> for sub, criteria in self.subscribers.items():
> if criteria(msg):
> sub.handle(msg)
>
> p = Publisher()
> p.subscribe(sub, lambda x: all(r > 3 for r in x.ratings))
>
> # So what I needed is:
> p.subscribe(sub, lambda x: set(r > 3 for r in x.ratings) > 50)
> # Note, that elements might not necessarily be bool.
> # E.g. at least 51 non-empty pages
> p.subscribe(sub, lambda x: set(bool(p) for p in x.pages) > 50)
> # So the function:
> p.subscribe(sub, lambda x: xor_more_than(x.pages, 50)
> # would ideally deal with truth values too.
> The question is: can you construct a function? which:
> a) performs: lambda x: set(bool(el) for el in iterable) > n
> b) is in line with performance of python’s `all`
>
> Then, as I said the case where one would need `set() == n` is hard to think of, but it seems fairly probable to need `set() > n` and `set() < n`.
>
> Regards,
> DG
>
>> On 15 Nov 2023, at 19:16, Peter J. Holzer via Python-list <python-list@python.org <mailto:python-list@python.org>> wrote:
>>
>> On 2023-11-15 12:26:32 +0200, Dom Grigonis wrote:
>>>
>>> Thank you,
>>>
>>>
>>> test2 = [True] * 100 + [False] * 2
>>> test2i = list(range(100))
>>>
>>> %timeit len(set(test2i)) == 1 # 1.6 µs ± 63.6 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
>>> %timeit all(test2) # 386 ns ± 9.58 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
>>>
>>> test2s = set(test2i)
>>> %timeit len(test2s) == 1 # 46.1 ns ± 1.65 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
>>>
>>> If you pre-convert to set it is obviously faster. However, set
>>> operation is most likely going to be part of the procedure. In which
>>> case it ends up to be significantly slower.
>>
>> Obviously, if you convert a list to a set just to count the elements
>> it's going to be slow. My suggestion was to use the set *instead* of the
>> list. I don't know whether that's possible in your situation, because
>> you haven't told us anything about it. All I'm suggesting is taking a
>> step back and reconsider your choice of data structure.
>>
>> hp
>> --
>> _ | Peter J. Holzer | Story must make more sense than reality.
>> |_|_) | |
>> | | | hjp@hjp.at <mailto:hjp@hjp.at> | -- Charles Stross, "Creative writing
>> __/ | http://www.hjp.at/ <http://www.hjp.at/> | challenge!"
>> --
>> https://mail.python.org/mailman/listinfo/python-list <https://mail.python.org/mailman/listinfo/python-list>
>

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor