Velocity Reviews > how to compare...

# how to compare...

jairodsl
Guest
Posts: n/a

 02-13-2007
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

James Stroud
Guest
Posts: n/a

 02-13-2007
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?

attn.steven.kuo@gmail.com
Guest
Posts: n/a

 02-13-2007
On Feb 12, 8:03 pm, "jairodsl" <(E-Mail Removed)> 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

Gabriel Genellina
Guest
Posts: n/a

 02-13-2007
En Tue, 13 Feb 2007 01:03:07 -0300, jairodsl <(E-Mail Removed)> 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

James Stroud
Guest
Posts: n/a

 02-13-2007
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.

Gerard Flanagan
Guest
Posts: n/a

 02-13-2007
On Feb 13, 5:03 am, "jairodsl" <(E-Mail Removed)> 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

jairodsl
Guest
Posts: n/a

 02-13-2007
On Feb 13, 4:30 am, "Gerard Flanagan" <(E-Mail Removed)> wrote:
> On Feb 13, 5:03 am, "jairodsl" <(E-Mail Removed)> 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

jDSL