Im trying to merge two lists that have a common thing between them (in that case is a the id
parameter).
I have something like this:
list1=[(id1,host1
You'll want to go through each of the two lists of lists and add their contents to a new defaultdict with elements of type list
.
This will have the effect of creating a dictionary with contents like {id1: (host1, host5), id2: host2, ...}
.
You can then go through and map the id
values to their corresponding IP
values.
Note that in order for this to work, the id
values have to be hashable. Strings, numbers, and other basic types are hashable.
If the id
values are objects of a class you've defined, you can have that class inherit from the collections.Hashable abstract base class.