# multiplication of lists of strings

Discussion in 'Python' started by Jason, Mar 5, 2008.

1. ### JasonGuest

How could I return a list or tuple of each unique combination of a given
set of lists (perhaps from a dict or a list). This means the number of
lists are not known nor is the length of each.

Here is an example:
fruit = ['apple', 'orange']
numbers = ['one', 'two', 'three']
names = ['joe']

Order matters (I started by trying to iterate over a list corresponding
to keys in the dict that contains these lists). Furthermore, (a, b) is
different from (b, a) however I will filter out all but unique (a, a) if
that occurs.

Once this step is solved, I then will use each tuple as a key in a dict.

I appreciate any assistance you can throw my way.

Jason G

Jason, Mar 5, 2008

2. ### Gabriel GenellinaGuest

En Tue, 04 Mar 2008 23:50:49 -0200, Jason <> escribió:

> How could I return a list or tuple of each unique combination of a given
> set of lists (perhaps from a dict or a list). This means the number of
> lists are not known nor is the length of each.

Use the Google interfase for this group:
Type "unique combinations lists" in the text box; press "Search in this

--
Gabriel Genellina

Gabriel Genellina, Mar 5, 2008

3. ### Jason GalyonGuest

Gabriel Genellina wrote:
> En Tue, 04 Mar 2008 23:50:49 -0200, Jason <> escribió:
>
>> How could I return a list or tuple of each unique combination of a given
>> set of lists (perhaps from a dict or a list). This means the number of
>> lists are not known nor is the length of each.

>
> Use the Google interfase for this group:
> Type "unique combinations lists" in the text box; press "Search in this
> group". The very first result contains some answers to your question.
>

found it, the referenced cookbook recipe is perfect.

Thanks, Gabriel

Jason Galyon, Mar 5, 2008
4. ### Guest

On Mar 4, 9:46 pm, Jason Galyon <> wrote:
> Gabriel Genellina wrote:
> > En Tue, 04 Mar 2008 23:50:49 -0200, Jason <> escribió:

>
> >> How could I return a list or tuple of each unique combination of a given
> >> set of lists (perhaps from a dict or a list).  This means the number of
> >> lists are not known nor is the length of each.

>
> > Use the Google interfase for this group:
> > Type "unique combinations lists" in the text box; press "Search in this
> > group". The very first result contains some answers to your question.

>
> found it, the referenced cookbook recipe is perfect.
>
> Thanks, Gabriel

That reminds me: Is there a generic 'relation' pattern/recipie, such
as finding a computer that's "paired" with multiple users, each of who
are "paired" with multiple computers, without maintaining dual-
associativity?

Good:

py> user.getcomputers()
[ Compie1, Compie2 ]

?

, Mar 5, 2008
5. ### Bruno DesthuilliersGuest

a écrit :
(snip)
>
> That reminds me: Is there a generic 'relation' pattern/recipie, such
> as finding a computer that's "paired" with multiple users, each of who
> are "paired" with multiple computers, without maintaining dual-
> associativity?
>

Yes : use a relational database.

Bruno Desthuilliers, Mar 5, 2008
6. ### Guest

On Mar 5, 2:16 am, Bruno Desthuilliers <bruno.
> wrote:
> a écrit :
> (snip)
>
> > That reminds me:  Is there a generic 'relation' pattern/recipie, such
> > as finding a computer that's "paired" with multiple users, each of who
> > are "paired" with multiple computers, without maintaining dual-
> > associativity?

>
> Yes : use a relational database.

No performance hit. Can I write an ad hoc relational class structure?

, Mar 8, 2008
7. ### Guest

On Mar 8, 12:04 pm, wrote:
> On Mar 5, 2:16 am, Bruno Desthuilliers <bruno.
>
> > wrote:
> > a écrit :
> > (snip)

>
> > > That reminds me:  Is there a generic 'relation' pattern/recipie, such
> > > as finding a computer that's "paired" with multiple users, each of who
> > > are "paired" with multiple computers, without maintaining dual-
> > > associativity?

>
> > Yes : use a relational database.

>
> No performance hit.  Can I write an ad hoc relational class structure?

What do you think of this solution?

http://jtauber.com/blog/2005/11/10/relational_python:_basic_class_for_relations/