On Tue, 5 Oct 2010 02:04:09 am David Hutto wrote:
> a = ['+','-','+','-','+','-','+','-','+','-','+']
> b = ['-','+','-','+','-','-','-','+','-','-','-']
>
> count = 0
> lena = len(a)
> lenb = len(b)
> if lena == lenb:
> for num in range(0,lena):
> if a[num] == b[num]:
> print 'match'
> count += 1
> else:
> print 'Lists are not same length for comparison'
> per = (100/lena)
> print count * per, '% match'
a = '+-+-+-+-+-+'
b = '-+-+---+---'
if len(a) != len(b):
raise ValueError('lists are not the same length')
count = sum(ca == cb for (ca, cb) in zip(a, b))
--
Steven D'Aprano
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor