multiplication of lists of strings

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

  1. Jason

    Jason Guest

    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
    #1
    1. Advertising

  2. 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:
    http://groups.google.com/group/comp.lang.python/
    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
    Gabriel Genellina, Mar 5, 2008
    #2
    1. Advertising

  3. Jason

    Jason Galyon Guest

    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:
    > http://groups.google.com/group/comp.lang.python/
    > 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
    #3
  4. Jason

    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:
    > >http://groups.google.com/group/comp.lang.python/
    > > 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 )

    ?
    , Mar 5, 2008
    #4
  5. 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
    #5
  6. Jason

    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
    #6
  7. Jason

    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/

    http://www.google.com/search?hl=en&q=python relational class -database
    , Mar 8, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. robin
    Replies:
    10
    Views:
    541
    Dave Hansen
    Apr 12, 2006
  2. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    399
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  3. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    754
    Malcolm
    Jun 24, 2006
  4. William Hughes
    Replies:
    13
    Views:
    1,213
    Ben Bacarisse
    Mar 15, 2010
  5. harryos
    Replies:
    6
    Views:
    758
    Peter Otten
    Sep 20, 2010
Loading...

Share This Page