On Sep 19, 2014 12:28 AM, "Danny Yoo" <d...@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.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to