I'm trying to merge two lists, base
and override
, where base
is supposed to be a larger list and override
is a subset of the things in base
. Where the elements overlap, I want the object in base
to be overwritten by the one in override
. The objects in each list are namedtuples with attributes al2000
and de2000
among them. Moreover I want to treat the objects as being "identical" when they have the same al2000
and de2000
values. What I have (which seems to work) is below, but this has nested loops, and I'm wondering if there is a better way to do this.
# Part of a function
final = []
for i in base:
if all((i.al2000, i.de2000) != (k.al2000, k.de2000) for k in override):
final.append(i)
else:
for k in override:
if (i.al2000, i.de2000) == (k.al2000, k.de2000):
final.append(k)
return final