[Tutor] Dictionaries

Walter Prins wprins at gmail.com
Fri Feb 10 15:38:27 CET 2012


Hi Myles,

On 10 February 2012 14:13, myles broomes <mylesbroomes at hotmail.co.uk> wrote:
> Ive been given a challenge in the book im learning Python from and its
> basically create a program with a dictionary of father - son pairs and allow
> the user to add, replace and delete pairs. Ive done that without any
> problems but ive been giving another challenge where I have to improve the
> previous program by adding a choice that lets the user enter a name and get
> back a grandfather. The program should still only use one dictionary of
> father-son pairs and finally I have to make sure to include several
> generations in your dictionary so that a match can be found. Im not sure I
> fully understand the task because surely its only possible to have one key
> and one value per pair but the challenge seems to want me to have a key (for
> the father), a value (for the son) and then something else (for the
> grandfather). Is this actually possible? Or am I just misinterpreting the
> challenge?

Sarma is correct. I'd like to add: Suppose you had a table with 2
columns, the first listing sons, the second their fathers.  And
suppose someone asked you to find the grandfather of someone.  How
would *you* go about finding the answer to this question, using the
table?  What steps would you execute?  If you can come up with an
explanation to my question, then your job is to translate this
solution into Python, but using your existing dictionary instead of
the table.

HTH,

Walter


More information about the Tutor mailing list