[Tutor] Comparing lists

Terje Johan Abrahamsen terjeja@hotmail.com
Tue, 09 Jul 2002 14:55:28 +0000


I am trying to find out if there is some number that exists in both lists. 
It doesn't matter if they are in the same place or not. I just want to find 
if some number exists in both lists, or if all numbers differs from all 
numbers in the other list.


>Are you trying to find out if 34 (or whatever else) exists in both lists
>*at all* or in the same place?
>
> >>> lista = [34, 42, 13]
> >>> listb = [42, 13, 34]
>
>These two lists, for instance, contain all the same values, but they are
>not identical due to the placement of the 34.
>
> >>> if lista == listb:
>	print 'equal'
>elif lista != listb:
>	print 'inequal'
>
>
>inequal
>
>Rob
>http://uselesspython.com
>
>Terje Johan Abrahamsen wrote:
>
>>I have two lists of different length. Actually each list can differ in
>>lenght every time. For example lista = [12, 34, 56] & listb = [14, 16,
>>34, 81]. What I now need to do is to check if the lists have one or more
>>common numbers. In this case 34 exists in each list. Then I would like
>>the function to somehow indicate this. Does it exist a simple way to do
>>this? I have made a somehow functioning function that does this, but it
>>is probably about 50-60 lines. (If lista[0] == listb[0], if lista[1] ==
>>listb[0] and so forth....)
>>
>>Any suggestions?
>>
>>Thanks,
>>Terje
>>
>>
>>
>>_________________________________________________________________
>>Join the world's largest e-mail service with MSN Hotmail.
>>http://www.hotmail.com
>>
>>
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>--
>"Giving the Linus Torvalds Award to the Free Software Foundation is a
>bit like giving the Han Solo Award to the Rebel Alliance."
>--Richard Stallman at the 1999 LinuxWorld show
>
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor




_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx