Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Killing is wrong. -- Losira, "That Which Survives", stardate unknown


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

SubjectAuthor
o Re: All permutations from 2 listsgene heskett

1
Re: All permutations from 2 lists

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ghesk...@shentel.net (gene heskett)
Newsgroups: comp.lang.python
Subject: Re: All permutations from 2 lists
Date: Wed, 02 Mar 2022 21:04:00 -0500
Organization: only accidental
Lines: 70
Message-ID: <mailman.108.1646273046.2329.python-list@python.org>
References: <CACwCsY4EQHJLr3k6G5nKdxp+Z0z_-gOLCFFtyEyDiAzym70xeA@mail.gmail.com>
<a8e2343e-c9c5-fd10-55e5-72bdfa704b22@vub.be>
<CACwCsY6GPA0y8RYRk1uYAeJ+K9f2D9zxTvkSA9O8VdjjaexOGQ@mail.gmail.com>
<2384304.IHPYU4O7oZ@coyote>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7Bit
X-Trace: news.uni-berlin.de Og5rCiDE2gAhUDTSiTlLnApYw8dOfl/FkmwuslYILFlA==
Return-Path: <gheskett@shentel.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; '2022': 0.05;
'received:204': 0.05; 'mar': 0.07; 'telling': 0.07; 'skip:[ 30':
0.09; 'cheers,': 0.11; '"there': 0.16; '-ed': 0.16; '>>>>': 0.16;
'>>>>>': 0.16; 'ammo.': 0.16; 'antoon': 0.16; 'ballot,': 0.16;
'brandeis': 0.16; 'desire': 0.16; 'empty,': 0.16; 'encounter':
0.16; 'from:addr:gheskett': 0.16; 'from:addr:shentel.net': 0.16;
'from:name:gene heskett': 0.16; 'genes': 0.16; 'howdershelt':
0.16; 'jury,': 0.16; 'liberty:': 0.16; 'order."': 0.16; 'pardon':
0.16; 'query.': 0.16; 'received:204.111': 0.16;
'received:204.111.64': 0.16; 'received:204.111.64.149': 0.16;
'respectable.': 0.16; 'schreef': 0.16; 'soap,': 0.16;
'subject:lists': 0.16; 'them?': 0.16; 'thread.': 0.16; 'url:6309':
0.16; 'url:gene': 0.16; 'url:geneslinuxbox': 0.16; 'want,': 0.16;
'wrote:': 0.16; 'to:addr:python-list': 0.20; 'list,': 0.24; "i'd":
0.24; 'suspect': 0.26; 'wednesday,': 0.26; '>>>': 0.28; 'seem':
0.31; 'header:Organization:1': 0.31; 'think': 0.32; 'empty': 0.32;
'guess': 0.32; "wouldn't": 0.32; 'but': 0.32; 'there': 0.33;
'march': 0.33; "didn't": 0.34; 'header:In-Reply-To:1': 0.34;
'respect': 0.35; 'lists': 0.37; 'subject:from': 0.37; 'using':
0.37; 'way': 0.38; 'could': 0.38; 'list': 0.39; 'use': 0.39;
'wed,': 0.39; 'case.': 0.40; 'want': 0.40; 'four': 0.60; 'law':
0.60; 'method': 0.61; 'above': 0.62; 'me.': 0.62; 'here': 0.62;
'pass': 0.64; 'down': 0.64; 'your': 0.64; 'produce': 0.65; 'less':
0.65; 'decided': 0.67; 'earlier': 0.67; 'prevent': 0.67; 'items':
0.68; 'skip:i 40': 0.68; 'url:net': 0.68; 'est': 0.69;
'following:': 0.69; 'law,': 0.69; 'through.': 0.69; 'url-ip:lookup
error': 0.70; 'deal': 0.73; 'handles': 0.76; '1940)': 0.84;
'received:mail': 0.84; 'subject:All': 0.84; 'want.': 0.84; 'skip:q
20': 0.95
auth-sender: gheskett@shentel.net
In-Reply-To: <CACwCsY6GPA0y8RYRk1uYAeJ+K9f2D9zxTvkSA9O8VdjjaexOGQ@mail.gmail.com>
X-CTCH-Spam: Unknown
X-CTCH-RefID: str=0001.0A702F1A.62202212.0026, ss=1, re=0.000, recu=0.000,
reip=0.000, cl=1, cld=1, fgs=0
X-OriginalArrivalTime: 03 Mar 2022 02:06:15.0581 (UTC)
FILETIME=[4394ECD0:01D82EA3]
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: <2384304.IHPYU4O7oZ@coyote>
X-Mailman-Original-References: <CACwCsY4EQHJLr3k6G5nKdxp+Z0z_-gOLCFFtyEyDiAzym70xeA@mail.gmail.com>
<a8e2343e-c9c5-fd10-55e5-72bdfa704b22@vub.be>
<CACwCsY6GPA0y8RYRk1uYAeJ+K9f2D9zxTvkSA9O8VdjjaexOGQ@mail.gmail.com>
 by: gene heskett - Thu, 3 Mar 2022 02:04 UTC

On Wednesday, 2 March 2022 10:49:11 EST Larry Martell wrote:
> On Wed, Mar 2, 2022 at 10:26 AM Antoon Pardon <antoon.pardon@vub.be>
wrote:
> > Op 2/03/2022 om 15:58 schreef Larry Martell:
> > > On Wed, Mar 2, 2022 at 9:37 AM Antoon Pardon<antoon.pardon@vub.be>
wrote:
> > >>>>> If one list is empty I want just the other list. What I am
> > >>>>> doing is
> > >>>>> building a list to pass to a mongodb query. If region is empty
> > >>>>> then I
> > >>>>> want to query for just the items in the os list. I guess I can
> > >>>>> test
> > >>>>> for the lists being empty, but I'd like a solution that handles
> > >>>>> that
> > >>>>> as down the road there could be more than just 2 lists.
> > >>>>
> > >>>> How about the following: Keep a list of your lists you want to
> > >>>> permute over. Like the following:
> > >>>>
> > >>>> permutation_elements = [["Linux","Windows"],["us-east-1",
> > >>>> "us-east-2"]]
> > >>>>
> > >>>> permutation = itertools.product(*permutation_elements)
> > >>>>
> > >>>> If you don't include the empty list, you will get more or less
> > >>>> what you seem to want.
> > >>>
> > >>> But I need to deal with that case.
> > >>
> > >> What does that mean? How does using the above method to produce
> > >> the permutations you want, prevent you from dealing with an empty
> > >> list however you want when you encounter them? Just don't add
> > >> them to the permutation_elements.> >
> > > I need to know what items are in which position. If sometimes the
> > > regions are in one index and sometimes in another will not work for
> > > me.
> >
> > I am starting to suspect you didn't think this through. What you are
> > telling here contradicts what you told earlier that if either list
> > was empty, you just wanted the other list. Because then you wouldn't
> > know what items were in that list.
> >
> > The only solution I can see now is that if a list is empty, you
> > either add [None] or [""] to the permutation_elements (whatever
> > suits you better) and then use itertools.product
>
> I found a way to pass this directly into the query:
>
> 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))

I take it back, kmail5 had decided it was a different thread. My bad, no
biscuit.

Cheers, Gene Heskett.
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
- Louis D. Brandeis
Genes Web page <http://geneslinuxbox.net:6309/gene>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor