Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

!07/11 PDP a ni deppart m'I !pleH


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.89.1646229691.2329.python-list@python.org>

  copy mid

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

  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: Wed, 2 Mar 2022 09:00:52 -0500
Lines: 50
Message-ID: <mailman.89.1646229691.2329.python-list@python.org>
References: <CACwCsY4EQHJLr3k6G5nKdxp+Z0z_-gOLCFFtyEyDiAzym70xeA@mail.gmail.com>
<Yh64QGJVQllpgenC@scrozzle>
<CACwCsY5yWusEWf9S6N8gCZ7ZtepwR=jBsiRqo4n7zheBMNSwhw@mail.gmail.com>
<f80357f5-9216-16aa-23e5-7ea4cce53c0b@vub.be>
<CACwCsY601s2HTa-0Upkj=90p2-2fZx8H8tXReCXUKd8ucdfgwQ@mail.gmail.com>
<CAPM-O+yBuXF709ddqByGeYauYfrB1E45N=iDLYRS+bEvcQ92Sw@mail.gmail.com>
<CACwCsY6Q+0bdBs=Lcfr-rP3XOZSLxpp-pSKLmvpXaeeRAM9Tsw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de Y2Fjh355ZsIdoS9jde8mcwyuo4B1fqWRgDcb3k6wPvhw==
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=jlqi1gq4;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.007
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '2022': 0.05; 'mar': 0.07;
'cc:addr:python-list': 0.09; 'url:mailman': 0.15; '8:37': 0.16;
'antoon': 0.16; 'cc:name:python': 0.16; 'collection.': 0.16;
'empty,': 0.16; 'itertools': 0.16; 'length.': 0.16; 'pardon':
0.16; 'query.': 0.16; 'received:209.85.208.180': 0.16; 'received
:mail-lj1-f180.google.com': 0.16; 'schreef': 0.16;
'subject:lists': 0.16; 'tuples': 0.16; 'wrote:': 0.16; 'tue,':
0.19; 'cc:addr:python.org': 0.20; 'list,': 0.24; "i'd": 0.24;
'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; 'tried': 0.26; '>>>': 0.28; 'url-ip:188/8': 0.31;
"doesn't": 0.32; 'question': 0.32; 'empty': 0.32; 'guess': 0.32;
'lists,': 0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32;
'there': 0.33; 'mean': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35; 'lists':
0.37; 'subject:from': 0.37; 'received:209.85': 0.37; 'could':
0.38; 'received:209': 0.39; 'two': 0.39; 'received:209.85.208':
0.39; 'valid': 0.39; 'list': 0.39; 'wed,': 0.39; 'wrote': 0.39;
'want': 0.40; 'should': 0.40; 'pass': 0.64; 'down': 0.64; 'items':
0.68; 'perfectly': 0.69; 'handles': 0.76; 'need.': 0.84;
'subject:All': 0.84; 'joel': 0.91
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=7TBd124l/72xo9KgaLcJBWf88oasGhGPNDk2puCC+lA=;
b=jlqi1gq4fenlFxTON2Z3rnpQUXVY9IoVPCZjlvcZ8/4LxPRctVjFMaUPg366KWdZ97
+jojpMYDP9le51d5u8NLIYsufgPMxiP/DpALcMj6bOFh23L4apcIOXR1bskVxLn2/cMR
5HWX+uDM6PCh85NII75hLbFeBWssrxE8eekXhJLWhNcWu4R0JqDr3Fl7kTbO05yKKZRi
SJYbUafVJBeDlW2J/X8Ek2FtwvrW+9YDOnpo/xuk9oiUiPpxjrPWGTjEooQwtwxlV+RW
I6KkP5c8H2sWp/+2ECqFKmvGyPfFSLQ4YWEoIHVl85GhvfwjIu/vQA2F5RbFxeSOOUWu
7XAQ==
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=7TBd124l/72xo9KgaLcJBWf88oasGhGPNDk2puCC+lA=;
b=jtWyWSvnyRSAjPhdc4R52s6XsS5QtF//QM9ZbC2W588PiwL7R/o0R6kJH9Lb2MeH3B
CyHNi9MKuseaZS6oCpwSMGjjr/TaupgK6mS/wbx4Qjcs0zr1HYez/VXNapZmqX3rQkME
GQ3fvzGN9sTPhNAyk4L2b35AWSEUGpYLjNLOcQlvX8tshW+ypRXW1unP9CAGjwFFQor3
ZesrDUG5DXHYWF1g0cqdB7u1O3MhKpJ/p0emL9A/iLgz9h4vMeIC5wALFadtPOmQ56q/
WtvSyprE0UU4FGiBbonIh/5LY+UO0ZaTwO12Rx/2VonQ4egfTnbNKFlHgTP//lb5nell
se/Q==
X-Gm-Message-State: AOAM532OkUDDKLPep+fmpe9d2QHvTIr0Ix8T4omcpGPwudIrUu64M6Nq
uUO2Z7oudQbihPlKlUEl88yRw9LLCGOaGXqJlCozLUs=
X-Google-Smtp-Source: ABdhPJzWUIqCu0qtLVymusDk2Qu+ah560RNyTZq/Md0zUfVpJy5hEeTNCexpZ3SAABU5wwb77SUOs+x6nqg6v7w+EbE=
X-Received: by 2002:a2e:6e14:0:b0:244:cbbe:c690 with SMTP id
j20-20020a2e6e14000000b00244cbbec690mr20161291ljc.169.1646229689215; Wed, 02
Mar 2022 06:01:29 -0800 (PST)
In-Reply-To: <CAPM-O+yBuXF709ddqByGeYauYfrB1E45N=iDLYRS+bEvcQ92Sw@mail.gmail.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: <CACwCsY6Q+0bdBs=Lcfr-rP3XOZSLxpp-pSKLmvpXaeeRAM9Tsw@mail.gmail.com>
X-Mailman-Original-References: <CACwCsY4EQHJLr3k6G5nKdxp+Z0z_-gOLCFFtyEyDiAzym70xeA@mail.gmail.com>
<Yh64QGJVQllpgenC@scrozzle>
<CACwCsY5yWusEWf9S6N8gCZ7ZtepwR=jBsiRqo4n7zheBMNSwhw@mail.gmail.com>
<f80357f5-9216-16aa-23e5-7ea4cce53c0b@vub.be>
<CACwCsY601s2HTa-0Upkj=90p2-2fZx8H8tXReCXUKd8ucdfgwQ@mail.gmail.com>
<CAPM-O+yBuXF709ddqByGeYauYfrB1E45N=iDLYRS+bEvcQ92Sw@mail.gmail.com>
 by: Larry Martell - Wed, 2 Mar 2022 14:00 UTC

On Wed, Mar 2, 2022 at 8:54 AM Joel Goldstick <joel.goldstick@gmail.com> wrote:
>
> On Wed, Mar 2, 2022 at 8:46 AM Larry Martell <larry.martell@gmail.com> wrote:
> >
> > On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon <antoon.pardon@vub.be> wrote:
> > >
> > >
> > > Op 2/03/2022 om 14:27 schreef Larry Martell:
> > > > On Tue, Mar 1, 2022 at 7:21 PM<2QdxY4RzWzUUiLuE@potatochowder.com> wrote:
> > > >> On 2022-03-01 at 19:12:10 -0500,
> > > >> Larry Martell<larry.martell@gmail.com> wrote:
> > > >>
> > > >>> If I have 2 lists, e.g.:
> > > >>>
> > > >>> os = ["Linux","Windows"]
> > > >>> region = ["us-east-1", "us-east-2"]
> > > >>>
> > > >>> How can I get a list of tuples with all possible permutations?
> > > >>>
> > > >>> So for this example I'd want:
> > > >>>
> > > >>> [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows",
> > > >>> "us-east-1"), "Windows", "us-east-2')]
> > > >>>
> > > >>> The lists can be different lengths or can be 0 length. Tried a few
> > > >>> different things with itertools but have not got just what I need.
> > > >> [(o, r) for o in os for r in region]
> > > > This does not work if region = []. I wrote in my question that either
> > > > list could be empty.
> > >
> > > What do you mean it doesn't work? The result seems to be an empty list,
> > > which IMO is a perfectly valid result.
> > >
> > > All possible permutations over two collections where one collection is
> > > empty, should IMO give you an empty collection.
> >
> > 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.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
> Does this help you out:
>
> >>> [(o,r) for o in opsys for r in region or "x"]
> [('Linux', 'x'), ('Window', 'x')]

That doesn't work if opsys = [] - either list could be empty.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor