[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

multiplication of lists of strings

Jason

3/5/2008 1:51:00 AM

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
6 Answers

Gabriel Genellina

3/5/2008 2:39:00 AM

0

En Tue, 04 Mar 2008 23:50:49 -0200, Jason <jasong@gmail.com> 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:
http://groups.google.com/group/comp.la...
Type "unique combinations lists" in the text box; press "Search in this
group". The very first result contains some answers to your question.

--
Gabriel Genellina

Jason

3/5/2008 3:47:00 AM

0

Gabriel Genellina wrote:
> En Tue, 04 Mar 2008 23:50:49 -0200, Jason <jasong@gmail.com> 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:
> http://groups.google.com/group/comp.la...
> 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

Aaron Brady

3/5/2008 3:51:00 AM

0

On Mar 4, 9:46 pm, Jason Galyon <jas...@gmail.com> wrote:
> Gabriel Genellina wrote:
> > En Tue, 04 Mar 2008 23:50:49 -0200, Jason <jas...@gmail.com> 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:
> >http://groups.google.com/group/comp.la...
> > 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 ]

Bad:

user._computers.add( compieN )
compieN._users.add( user )

?

Bruno Desthuilliers

3/5/2008 8:17:00 AM

0

castironpi@gmail.com 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.

Aaron Brady

3/8/2008 6:04:00 PM

0

On Mar 5, 2:16 am, Bruno Desthuilliers <bruno.
42.desthuilli...@wtf.websiteburo.oops.com> wrote:
> castiro...@gmail.com 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?

Aaron Brady

3/8/2008 6:11:00 PM

0

On Mar 8, 12:04 pm, castiro...@gmail.com wrote:
> On Mar 5, 2:16 am, Bruno Desthuilliers <bruno.
>
> 42.desthuilli...@wtf.websiteburo.oops.com> wrote:
> > castiro...@gmail.com 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_...

http://www.google.com/search?hl=en&q=python+relational+class...