how to compare...

Discussion in 'Python' started by jairodsl, Feb 13, 2007.

  1. jairodsl

    jairodsl Guest

    Hello everybody !


    I have two list, they are, S1=['A','B','C','D','E'], and
    S2=['F','G','H','I','J'], but i have to compare both in this way:

    A vs J
    A vs I, B vs J
    A vs H, B vs I, C vs J
    A vs G, B vs H, C vs I, D vs J
    A vs F, B vs G, C vs H, D vs I, E vs J
    B vs F, C vs G, D vs H, E vs I
    C vs F, D vs G, E vs H
    D vs F, E vs G
    E vs F

    Perhaps, you should understand better in this way:

    A
    J

    A B
    I J

    A B C
    H I J

    A B C D
    G H I J

    A B C D E
    F G H I J

    B C D E
    F G H I

    C D E
    F G H

    D E
    F G

    E
    F

    Could someone give me any idea how to compare(or print) both list in
    this way ??? Thanks a lot !!!

    jDSL
    jairodsl, Feb 13, 2007
    #1
    1. Advertising

  2. jairodsl

    James Stroud Guest

    jairodsl wrote:
    > Hello everybody !
    >
    >
    > I have two list, they are, S1=['A','B','C','D','E'], and
    > S2=['F','G','H','I','J'], but i have to compare both in this way:
    >
    > A vs J
    > A vs I, B vs J
    > A vs H, B vs I, C vs J
    > A vs G, B vs H, C vs I, D vs J
    > A vs F, B vs G, C vs H, D vs I, E vs J
    > B vs F, C vs G, D vs H, E vs I
    > C vs F, D vs G, E vs H
    > D vs F, E vs G
    > E vs F
    >
    > Perhaps, you should understand better in this way:
    >
    > A
    > J
    >
    > A B
    > I J
    >
    > A B C
    > H I J
    >
    > A B C D
    > G H I J
    >
    > A B C D E
    > F G H I J
    >
    > B C D E
    > F G H I
    >
    > C D E
    > F G H
    >
    > D E
    > F G
    >
    > E
    > F
    >
    > Could someone give me any idea how to compare(or print) both list in
    > this way ??? Thanks a lot !!!
    >
    > jDSL
    >

    for i in xrange(1, len(S1)+1):
    print S1[0:i]
    print S2[-i:]
    print

    Am I really the first person to respond to this?
    James Stroud, Feb 13, 2007
    #2
    1. Advertising

  3. jairodsl

    Guest

    On Feb 12, 8:03 pm, "jairodsl" <> wrote:
    > Hello everybody !
    >
    > I have two list, they are, S1=['A','B','C','D','E'], and
    > S2=['F','G','H','I','J'], but i have to compare both in this way:
    >
    > A vs J
    > A vs I, B vs J
    > A vs H, B vs I, C vs J
    > A vs G, B vs H, C vs I, D vs J
    > A vs F, B vs G, C vs H, D vs I, E vs J
    > B vs F, C vs G, D vs H, E vs I
    > C vs F, D vs G, E vs H
    > D vs F, E vs G
    > E vs F
    >


    (snipped)

    > Could someone give me any idea how to compare(or print) both list in
    > this way ??? Thanks a lot !!!
    >
    > jDSL




    s1 = [ 'A', 'B', 'C', 'D', 'E' ]
    s2 = [ 'F', 'G', 'H', 'I', 'J' ]
    s3 = []

    for count in xrange( len(s1) + len(s2) - 1 ):
    try:
    operand = s2.pop()
    except IndexError:
    operand = None
    except:
    raise
    s3.insert(0,operand)
    print [ t for t in zip(s1, s3) if t[1] is not None ]


    --
    Hope this helps,
    Steven
    , Feb 13, 2007
    #3
  4. En Tue, 13 Feb 2007 01:03:07 -0300, jairodsl <> escribió:

    > I have two list, they are, S1=['A','B','C','D','E'], and
    > S2=['F','G','H','I','J'], but i have to compare both in this way:
    >
    > A vs J
    > A vs I, B vs J
    > A vs H, B vs I, C vs J
    > A vs G, B vs H, C vs I, D vs J
    > A vs F, B vs G, C vs H, D vs I, E vs J
    > B vs F, C vs G, D vs H, E vs I
    > C vs F, D vs G, E vs H
    > D vs F, E vs G
    > E vs F


    And what to do after comparing each pair?

    Anyway, this would be one general approach: First, forget about the lists.
    Use numbers instead of letters (0 to 4), and try to generate the pairs of
    numbers needed. Once your program can generate the right number pairs, use
    those numbers as indexes into the lists.

    --
    Gabriel Genellina
    Gabriel Genellina, Feb 13, 2007
    #4
  5. jairodsl

    James Stroud Guest

    James Stroud wrote:
    > jairodsl wrote:
    >
    >> Hello everybody !
    >>
    >>
    >> I have two list, they are, S1=['A','B','C','D','E'], and
    >> S2=['F','G','H','I','J'], but i have to compare both in this way:
    >>
    >> A vs J
    >> A vs I, B vs J
    >> A vs H, B vs I, C vs J
    >> A vs G, B vs H, C vs I, D vs J
    >> A vs F, B vs G, C vs H, D vs I, E vs J
    >> B vs F, C vs G, D vs H, E vs I
    >> C vs F, D vs G, E vs H
    >> D vs F, E vs G
    >> E vs F
    >>
    >> Perhaps, you should understand better in this way:
    >>
    >> A
    >> J
    >>
    >> A B
    >> I J
    >>
    >> A B C
    >> H I J
    >>
    >> A B C D
    >> G H I J
    >>
    >> A B C D E
    >> F G H I J
    >>
    >> B C D E
    >> F G H I
    >>
    >> C D E
    >> F G H
    >>
    >> D E
    >> F G
    >>
    >> E
    >> F
    >>
    >> Could someone give me any idea how to compare(or print) both list in
    >> this way ??? Thanks a lot !!!
    >>
    >> jDSL
    >>

    > for i in xrange(1, len(S1)+1):
    > print S1[0:i]
    > print S2[-i:]
    > print
    >
    > Am I really the first person to respond to this?
    >


    I didn't scroll far enough down.
    James Stroud, Feb 13, 2007
    #5
  6. On Feb 13, 5:03 am, "jairodsl" <> wrote:
    > Hello everybody !
    >
    > I have two list, they are, S1=['A','B','C','D','E'], and
    > S2=['F','G','H','I','J'], but i have to compare both in this way:
    >
    > A vs J
    > A vs I, B vs J
    > A vs H, B vs I, C vs J
    > A vs G, B vs H, C vs I, D vs J
    > A vs F, B vs G, C vs H, D vs I, E vs J
    > B vs F, C vs G, D vs H, E vs I
    > C vs F, D vs G, E vs H
    > D vs F, E vs G
    > E vs F


    > Could someone give me any idea how to compare(or print) both list in
    > this way ??? Thanks a lot !!!
    >
    > jDSL


    def interleave( X, Y ):
    for i in range(1, len(Y)+1):
    yield zip(X, Y[-i:])
    for j in range(1, len(X)):
    yield zip(X[j:], Y)

    x = ['A', 'B', 'C', 'D', 'E']
    y = ['F', 'G', 'H', 'I', 'J']

    for seq in interleave(x, y):
    print seq

    [('A', 'J')]
    [('A', 'I'), ('B', 'J')]
    [('A', 'H'), ('B', 'I'), ('C', 'J')]
    [('A', 'G'), ('B', 'H'), ('C', 'I'), ('D', 'J')]
    [('A', 'F'), ('B', 'G'), ('C', 'H'), ('D', 'I'), ('E', 'J')]
    [('B', 'F'), ('C', 'G'), ('D', 'H'), ('E', 'I')]
    [('C', 'F'), ('D', 'G'), ('E', 'H')]
    [('D', 'F'), ('E', 'G')]
    [('E', 'F')]

    Regards

    Gerard
    Gerard Flanagan, Feb 13, 2007
    #6
  7. jairodsl

    jairodsl Guest

    On Feb 13, 4:30 am, "Gerard Flanagan" <> wrote:
    > On Feb 13, 5:03 am, "jairodsl" <> wrote:
    >
    >
    >
    > > Hello everybody !

    >
    > > I have two list, they are, S1=['A','B','C','D','E'], and
    > > S2=['F','G','H','I','J'], but i have to compare both in this way:

    >
    > > A vs J
    > > A vs I, B vs J
    > > A vs H, B vs I, C vs J
    > > A vs G, B vs H, C vs I, D vs J
    > > A vs F, B vs G, C vs H, D vs I, E vs J
    > > B vs F, C vs G, D vs H, E vs I
    > > C vs F, D vs G, E vs H
    > > D vs F, E vs G
    > > E vs F
    > > Could someone give me any idea how to compare(or print) both list in
    > > this way ??? Thanks a lot !!!

    >
    > > jDSL

    >
    > def interleave( X, Y ):
    > for i in range(1, len(Y)+1):
    > yield zip(X, Y[-i:])
    > for j in range(1, len(X)):
    > yield zip(X[j:], Y)
    >
    > x = ['A', 'B', 'C', 'D', 'E']
    > y = ['F', 'G', 'H', 'I', 'J']
    >
    > for seq in interleave(x, y):
    > print seq
    >
    > [('A', 'J')]
    > [('A', 'I'), ('B', 'J')]
    > [('A', 'H'), ('B', 'I'), ('C', 'J')]
    > [('A', 'G'), ('B', 'H'), ('C', 'I'), ('D', 'J')]
    > [('A', 'F'), ('B', 'G'), ('C', 'H'), ('D', 'I'), ('E', 'J')]
    > [('B', 'F'), ('C', 'G'), ('D', 'H'), ('E', 'I')]
    > [('C', 'F'), ('D', 'G'), ('E', 'H')]
    > [('D', 'F'), ('E', 'G')]
    > [('E', 'F')]
    >
    > Regards
    >
    > Gerard


    Thank you very much for all your answers.

    jDSL
    jairodsl, Feb 13, 2007
    #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. Tony Benham
    Replies:
    3
    Views:
    3,072
    Valentin Tihomirov
    Nov 2, 2003
  2. Matthias Alles

    compare unsigned

    Matthias Alles, May 14, 2004, in forum: VHDL
    Replies:
    1
    Views:
    3,309
    Mike Treseler
    May 14, 2004
  3. Thomas Reinemann

    How to compare strings

    Thomas Reinemann, May 27, 2004, in forum: VHDL
    Replies:
    0
    Views:
    625
    Thomas Reinemann
    May 27, 2004
  4. YC
    Replies:
    1
    Views:
    4,830
    siva chelliah
    Aug 13, 2003
  5. Frodo Larik
    Replies:
    1
    Views:
    1,627
    Jürgen Exner
    May 30, 2004
Loading...

Share This Page