So I have two protorpc.messages.FieldList. I would like to compute the symmetrical difference between the fields (Field class) in the two lists. I tried doing the following code.
list1 and list2 are my FieldLists, they each have three elements. Two of which are the same and one of which is difference. I expect the output to give me the elements that are different. I ran the following code.
set1 = set(list1)
set2 = set(list2)
difference = set1 ^ set2
However, the variable difference ended up holding all six of the fields.
When I try doing it with the following method it worked as expected.
difference = []
for item in list1:
if item not in list2:
difference.append(item)
So my question is, how does Python compute the symmetrical difference between two sets? Does it leverage equality (by values) or use the in operator (by reference)? Is there something else at play that I'm not seeing?
Edit to add example (this is inspired by protorpc documentation):
https://cloud.google.com/appengine/docs/python/tools/protorpc/?csw=1#Adding_Message_Fields
class GetNotesRequest(messages.Message):
notes= messages.SomeCustomField(1, repeated=true)
The lists that I'm getting are from repeated fields in these message containers.