I have a list of objects that contain information of a user such as their username, userID and other attributes. I have another list that contains strings of usernames. Usernames are unique and will not be identical to another user's.
From these two lists, I would like to find which users are in both lists based on their username.
When comparing the list of strings to the Name attribute of a user object, if two usernames that appear identical are found, the equality check returns false.
For example, if one of the user objects has a Username attribute of "Gerald" and in my list of usernames "Gerald" is an item in that list, when comparing the two it always returns false.
# users is a list of user objects. A user object has a Username attribute that stores a string.
# names is a list of strings of usernames.
for user in users:
for name in names:
# The if statement below always returns false.
if name == user.Name:
# perform desired operations when a match is found here...
break
I do not understand why two strings in this scenario cannot be compared.
Can attributes of an object not be compared to a variable of the same data type?