Specifics of List Membership

Posted by phasetwenty on Stack Overflow See other posts from Stack Overflow or by phasetwenty
Published on 2010-06-15T22:53:07Z Indexed on 2010/06/15 23:12 UTC
Read the original article Hit count: 176

Filed under:
|

How does Python (2.6.4, specifically) determine list membership in general? I've run some tests to see what it does:

def main():
    obj = fancy_obj(arg='C:\\')
    needle = (50, obj)
    haystack = [(50, fancy_obj(arg='C:\\')), (1, obj,), needle]

    print (1, fancy_obj(arg='C:\\'),) in haystack
    print needle in haystack

if __name__ == '__main__':
    main()

Which yields:

False
True

This tells me that Python is probably checking the object references, which makes sense. Is there something more definitive I can look at?

© Stack Overflow or respective owner

Related posts about python

Related posts about lists