Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to compare...

Reply
Thread Tools

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

 
Reply With Quote
 
 
 
 
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?

 
Reply With Quote
 
 
 
 
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

 
Reply With Quote
 
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

 
Reply With Quote
 
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.
 
Reply With Quote
 
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

 
Reply With Quote
 
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


Thank you very much for all your answers.

jDSL

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM



Advertisments