Re: All Possible Combinations from N Sublists

• To: mathgroup at smc.vnet.net
• Subject: [mg97655] Re: All Possible Combinations from N Sublists
• From: nma <marxer at mec.li>
• Date: Wed, 18 Mar 2009 04:52:18 -0500 (EST)
• References: <gpnsej\$gq4\$1@smc.vnet.net>

```On 17 Mrz., 11:01, Donald DuBois <don... at comcast.net> wrote:
> Given a list of N sublists, how can I produce all possible combinations w=
here the first
> element comes from the first sublst, the second element from the second s=
ublist etc.
>
> For instance,
>
> myList = {{1, 2, 3}, {e, f}, {g, h}}
>
> the result should be,
>
> {{1, e, g}, {1, e, h}, {1, f, g}, {1, f, h}, {2, e, g}, {2, e, h}, {2, f,
>   g}, {2, f, h}, {3, e, g}, {3, e, h}, {3, f, g}, {3, f, h}}
>
> Thank you.

Hello

One of the many solutions would be:

myList = {{1, 2, 3}, {e, f}, {g, h}}
Outer[List, Sequence @@ myList] // Flatten[#1, 2] &

Best Regards
Norbert Marxer

```

• Prev by Date: Re: All Possible Combinations from N Sublists
• Next by Date: Re: All Possible Combinations from N Sublists
• Previous by thread: Re: All Possible Combinations from N Sublists
• Next by thread: Re: All Possible Combinations from N Sublists