Merge Two List of Dict

Tim Chase python.list at tim.thechases.com
Thu Dec 1 07:08:33 EST 2016


On 2016-12-01 12:44, Nikhil Verma wrote:
> A = [{'person_id': '1', 'adop_count': '2'}, {'person_id': '3',
> 'adop_count': '4'}]
> *len(A) might be above 10L*
> 
> B = [{'person_id': '1', 'village_id': '3'}, {'person_id': '3',
> 'village_id': '4'}]
> *len(B) might be above 20L*
> 
> 
> OutPut List should be
> 
> C = B = [{'adop_count': '2', 'village_id': '3'}, {'adop_count': '4',
> 'village_id': '4'}]

You omit some details that would help:

- what happened to "person_id" in the results?  Just drop it?

- can duplicates of "person_id" appear in either A or B?  If so, what
  should happen in the output?

- can a "person_id" appear in A or B but not appear in the other?

- is A always just person_id/adop_count and is B always
  person_id/village_id, or can other data appear in (or be absent
  from) each dict?

Your answers would change the implementation details.

-tkc




More information about the Python-list mailing list