All permutations from 2 lists
2QdxY4RzWzUUiLuE at potatochowder.com
2QdxY4RzWzUUiLuE at potatochowder.com
Tue Mar 1 19:20:16 EST 2022
On 2022-03-01 at 19:12:10 -0500,
Larry Martell <larry.martell at 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]
Feel free to import itertools, but it's not really necessary. ;-)
More information about the Python-list
mailing list