469,365 Members | 1,945 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,365 developers. It's quick & easy.

Comparing lists ...

I would like to know if it is possible, and how to do this with Python:

I want to design a function to compare lists and return True only if
both lists are equal considering memory location of the list.
I suppose it would be the equivalent of comparing 2 pointers in c++

lets call this function check(a, b)
and define a few lists:
>>l0 = [1, 2, 3, 4]
l1 = [1, 2, 3, 4]
l2 = l0
I want it to have the following behaviour:
>>check(l1, l0)
False
>>check(l2, l0)
True
>>check(l1, l2)
False
Any idea how to do this with Python?
Feb 14 '07 #1
2 1941
Loic wrote:
I would like to know if it is possible, and how to do this with Python:

I want to design a function to compare lists and return True only if
both lists are equal considering memory location of the list.
I suppose it would be the equivalent of comparing 2 pointers in c++

lets call this function check(a, b)
and define a few lists:
>>l0 = [1, 2, 3, 4]
>>l1 = [1, 2, 3, 4]
>>l2 = l0

I want it to have the following behaviour:
>>check(l1, l0)
False
>>check(l2, l0)
True
>>check(l1, l2)
False
Any idea how to do this with Python?
Use "is". E.g.:

l0 is l1

James
Feb 14 '07 #2
Loic <lo**@spam.mewrites:
I want to design a function to compare lists and return True only if
both lists are equal considering memory location of the list.
I suppose it would be the equivalent of comparing 2 pointers in c++
Use the "is" keyword.

print (l1 is l2)
print (l0 is l2)
Feb 14 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by AJ | last post: by
10 posts views Thread by BoĆĄtjan Jerko | last post: by
41 posts views Thread by Odd-R. | last post: by
7 posts views Thread by andreas | last post: by
11 posts views Thread by John Salerno | last post: by
11 posts views Thread by Sheldon | last post: by
3 posts views Thread by Sean Dalton | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.