[Tutor] Question on List of Dict

Danny Yoo dyoo at hashcollision.org
Fri Sep 19 09:52:21 CEST 2014


On Sep 19, 2014 12:28 AM, "Danny Yoo" <dyoo at hashcollision.org> wrote:
>
>
> >        {'a': 2, 'b': 'another', 'c': 754},
> >        {'a': 2, 'b': 'word', 'c': 745}
> >
>
> > if the value of the 'a' is same, then all those other values of the
dict should be merged/clubbed.
>
> Can you write a function that takes two of these and merges them?  Assume
that they have the same 'a'.  Can you write such a function?

Specifically, can you write a function merge_two() such that:

    merge_two({''b': 'another', 'c': 754}, {'b': 'word', 'c': 745})

returns the merged dictionary:

   {'b' : ['another', 'word'], 'c':[754, 745]}

I'm trying to break the problem into simpler, testable pieces that you can
solve.  The problem as described is large enough that I would not dare
trying to solve it all at once.  If you have merge_two(), them you are much
closer to a solution to the whole problem.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140919/dffd9518/attachment-0001.html>


More information about the Tutor mailing list