469,271 Members | 1,466 Online

# how to compare...

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

Feb 13 '07 #1
6 1126 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?

Feb 13 '07 #2
On Feb 12, 8:03 pm, "jairodsl" <jairo...@gmail.comwrote:
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 is not None ]
--
Hope this helps,
Steven

Feb 13 '07 #3
En Tue, 13 Feb 2007 01:03:07 -0300, jairodsl <ja******@gmail.comescribió:
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

Feb 13 '07 #4
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.
Feb 13 '07 #5
On Feb 13, 5:03 am, "jairodsl" <jairo...@gmail.comwrote:
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

Feb 13 '07 #6
On Feb 13, 4:30 am, "Gerard Flanagan" <grflana...@yahoo.co.ukwrote:
On Feb 13, 5:03 am, "jairodsl" <jairo...@gmail.comwrote:
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