Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

When we write programs that "learn", it turns out we do and they don't.


devel / comp.lang.python / Re: All permutations from 2 lists

SubjectAuthor
o Re: All permutations from 2 listsLarry Martell

1
Re: All permutations from 2 lists

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: larry.ma...@gmail.com (Larry Martell)
Newsgroups: comp.lang.python
Subject: Re: All permutations from 2 lists
Date: Thu, 3 Mar 2022 09:07:42 -0500
Lines: 39
Message-ID: <mailman.115.1646316501.2329.python-list@python.org>
References: <1388685953.247061.1646275320253.ref@mail.yahoo.com>
<1388685953.247061.1646275320253@mail.yahoo.com>
<CACwCsY75Y4TtcY+xySf-UBoE=Mh3XbvQ7jdBaYfbhg7o_jnyGw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de HNhfzcp49hd8OTjAaxTCFgMBWjpD2FmT0R6BjeG7dFiw==
Return-Path: <larry.martell@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=d6i9uR5i;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.040
X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'def': 0.04; '2022': 0.05;
'mar': 0.07; 'cc:addr:python-list': 0.09; 'filtering': 0.09;
'originally': 0.09; 'received:209.85.219': 0.09; 'that.': 0.15;
'avi': 0.16; 'case:': 0.16; 'database.': 0.16; 'dict': 0.16;
'gross': 0.16; 'indeed': 0.16; 'specify': 0.16; 'subject:lists':
0.16; 'wrote:': 0.16; 'values': 0.17; 'cc:addr:python.org': 0.20;
'issue': 0.21; 'anything': 0.25; 'cc:2**0': 0.25; 'interests':
0.26; 'solution.': 0.26; 'seem': 0.31; 'empty': 0.32; 'guess':
0.32; 'python-list': 0.32; 'message-id:@mail.gmail.com': 0.32;
'but': 0.32; 'there': 0.33; 'work.': 0.34; 'header:In-Reply-To:1':
0.34; 'received:google.com': 0.34; 'trying': 0.35;
'from:addr:gmail.com': 0.35; 'lists': 0.37; 'subject:from': 0.37;
"it's": 0.37; 'received:209.85': 0.37; 'hard': 0.37; 'others':
0.37; 'this.': 0.37; 'way': 0.38; 'could': 0.38; 'means': 0.38;
'received:209': 0.39; 'single': 0.39; 'list': 0.39; 'use': 0.39;
'wed,': 0.39; 'explain': 0.40; 'something': 0.40; 'gave': 0.61;
'skip:o 10': 0.61; 'come': 0.62; 'true': 0.63; 'pass': 0.64;
'clear': 0.64; 'down': 0.64; 'source.': 0.64; 'outside': 0.67;
'presenting': 0.69; 'product': 0.71; 'cross': 0.76; 'need.': 0.84;
'field,': 0.84; 'pairs': 0.84; 'subject:All': 0.84; 'waited':
0.84; 'skip:q 20': 0.95
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=nCrd3m8lQ/jeiqvvvzQS67vhagkqpKN0DJfcw+YjWKI=;
b=d6i9uR5ioCl6Ti3kka4NKd6UO7EeZ4qlpIxc3JlXeGwclRvbRMcavDJ6adcj+pddD2
8wBNwMJ8knA8ycJ9IV2IxwGZgtuIH4EUtPJzfuvjFxbbnOuopURkNK0+LWwoSMqWf4xP
jJlvBUkL6iw7KunT5HPv1SLiqWU3KEEEFcIZ87kfg7rizOi5K2pVjQNaTmdZbVqbDRgk
QLLdbXkAUw+7XTJ/1y0R2w3hfVxk6Jh0ho8L6k1vbVRkGYY9d5MVmFw11ZW2tI2y1os7
/CBF9P2WShbzwhHX5a3nNARv5XN+WKDMtT1HI9wiR723Hpl0q0wyFaExTV8/bvg0Xh2t
IWag==
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=nCrd3m8lQ/jeiqvvvzQS67vhagkqpKN0DJfcw+YjWKI=;
b=h3AsxCbtr1WbdPlr6bg3xCIa7VUlOI75tAliYzue6UiyuZfrrnnsA+Fd3kMnNLKK7g
/VrVHOzrhqkjVDlpVj5OqAGjlfdl7oqjYBV8PggKGOps0wk8+Mwz03iG+2auUpCC4Via
g7h7NlDBC/6A5PTBpDWfFEw846IgDMcSyJptaKmQu8Pu21Cw0eWPKv4Kp+8k4cXFsub8
rTA7oxWZeiKk8ijy5ofmZbxph1XZHlKD+HmnCtW4so7AyfDHdt7CHCh6waN9rAm9bt+O
VNY5K3RPAeOOZ8zjLCfBkbok7VdOuBu7XIhksWpMW1rxmHd2Lkky0bSFjG/VNySck36o
fOFA==
X-Gm-Message-State: AOAM530zjR4yGh7wyTd6oW/GMqZg1riuPAHa37qW2sHK8GOAkkZBOMXm
WEGONIASI9pQ6kni6l2LEyEa6adG98TJ1UW7dQ==
X-Google-Smtp-Source: ABdhPJwkGvHetAg22VWtba7LLXv3r2pLzpwlJnXbyN1fAgEB89F4Nm/10tdB3b17Yu6s9x0yf71+HVLq5g2PzSMOq6c=
X-Received: by 2002:a05:6214:27e4:b0:42e:a257:b77c with SMTP id
jt4-20020a05621427e400b0042ea257b77cmr24532146qvb.62.1646316498997; Thu, 03
Mar 2022 06:08:18 -0800 (PST)
In-Reply-To: <1388685953.247061.1646275320253@mail.yahoo.com>
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: <CACwCsY75Y4TtcY+xySf-UBoE=Mh3XbvQ7jdBaYfbhg7o_jnyGw@mail.gmail.com>
X-Mailman-Original-References: <1388685953.247061.1646275320253.ref@mail.yahoo.com>
<1388685953.247061.1646275320253@mail.yahoo.com>
 by: Larry Martell - Thu, 3 Mar 2022 14:07 UTC

On Wed, Mar 2, 2022 at 9:42 PM Avi Gross via Python-list
<python-list@python.org> wrote:
>
> Larry,
>
> i waited patiently to see what others will write and perhaps see if you explain better what you need. You seem to gleefully swat down anything offered. So I am not tempted to engage.

But then you gave in to the temptation.

> And it is hard to guess as it is not clear what you will do with this.

In the interests of presenting a minimal example I clearly
oversimplified. This is my use case: I get a dict from an outside
source. The dict contains key/value pairs that I need to use to query
a mongodb database. When the values in the dict are all scalar I can
pass the dict directly into the query, e.g.:
self._db_conn[collection_name].find(query). But if any of the values
are lists that does not work. I need to query with something like the
cross product of all the lists. It's not a true product since if a
list is empty it means no filtering on that field, not no filtering on
all the fields. Originally I did not know I could generate a single
query that did that. So I was trying to come up with a way to generate
a list of all the permutations and was going to issue a query for each
individually. Clearly that would become very inefficient if the lists
were long or there were a lot of lists. I then found that I could
specify a list with the "$in" clause, hence my solution.

> def query_lfixer(query):
> for k, v in query.items():
> if type(v)==list:
> query[k] = {"$in": v}
> return query
>
> self._db_conn[collection_name].find(query_lfixer(query))
>
>
> So why did so many of us bother?

Indeed - so why did you bother?

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor