oh wow... this was waaaay more feedback then i was expecting in such short time
Maybe this will help
http://stackoverflow.com/questions/8023306/get-key-by-value-in-dictionary
i think i looked at that link earlier when searching around myself, but i didn't really understnad all of what was going on, there where functions i've never dealt with yet wich made it a bit too much for me to really grasp what they where doing.
DaveLembke, the challenge is to do it with a dictionary, but otherwise it sounds really smart and like something that's waaaaaaaay over the scale of my small python beginner challenge xD there is no file it's writing to it will just be a single file containing the program itself, i'm hardcoding the dictionary with some predefined values, and the user will be able to add/remove stuff but i won't be saving the changes or addittions anywhere, it's simply a code challenge to help me learn python
The answer is: You don't.
Well, not really. You CAN search a dictionary for a key given a value- but it's going to be a sequential search- you'd have to look through every item and find the one with the correct value. You would also have to decide what to do when more than one key has the same value. Fact is, this is slow and very poor design, because you are basically misusing the Dictionary.
As a solution, We can discount adding the reverse association to the dictionary- eg, the son key returns the father key as well, because this would mean that a son could not be a father which would obviously be no good for your required scalability to include grandfathers.
The solution, IMO, would be to maintain two Dictionaries. One that indexes the sons by their father, and one that indexes fathers by their sons (the one you already have). when you add one in you add the appropriate values to each dictionary; when you define that Bob is the Son of George, for example, you add Bob with the Key George to your existing dictionary, but you also add George with the key Bob to the second dictionary; then you use the correct dictionary based on how you are searching.
Of course, this means that any father can only ever have one son, which is implied somewhat anyway since your original dictionary couldn't have more than one son indexed by the father anyway.
Realistically if the desire is to create a more full "Family Tree" than you would want to explore the creation of an Actual Tree Data structure.
seems to be following the theme of tonight
while these answers have been rolling in i got some help from a friend on facebook, who's been going over this with me, and yes i understand that what i'm asking for help to do is breaking dictionaries and any real world applications xD
my friend also suggested doing 2 dictionaries, challenge with the grandfather part, says i have to do it inside one dictionary,
to give you a better idea i'll write out the entire challenge as it stands in the book i'm following
Write a Who's Your Daddy? program that lets the user enter the name of a male and produces the name of his father.
Allow the user to add, replace, and delete son-father pairs.
Improve the Who's Your Daddy? program by adding a choice that lets the user enter a name and get back a grandfather. Your program should still only use one dictionary of son-father pairs.
Make sure to include several generations in your dictionary so that a match can be found.
after talking to my friend i've been thinking about doing it as a dictionary where the son's name is gonna be the key, and the value will be a list containing his father and grandfather, it seems to be the way to go about making this work within the "rules" of the challenges