Forums

Simple logic in code not working on PythonAnywhere

I have a list of companies and I'm doing a check to see if a company is present in this list.

([<Company 10>, <Company 11>, <Company 12>, <Company 13>, <Company 16>, <Company 14>, <Company 17>, <Company 18>, <Company 19>, <Company 20>, <Company 22>], [<Company 15>, <Company 5>, <Company 6>])

Below is a simple check I am carrying out to see if a value is in the company list.

if owner in company_lists[0]:
    print('Owner in list')
else:
    print('Owner not in list')

I am printing out the value of owner company for each check and below is an example output

Owner is <Company 10>
Reseller is <Company 6>
Owner not in list

Am I missing something? As far as I can see both values are present in the list but I am not getting the expected output?

The most likely cause of the problem is that one instance of the company object may not compare equal to a different instance, even though they may have the same string representation. Try to create 2 different instances of Company 10 and then see if company1 == company2 returns True.