Hey guys, I'm having a problem with a very simple database test. I need to be able to find the key to a specific value, and check to see if a value exists. This is what I have (I've bolded the parts that I need help on, and put in fake methods that hopefully explain what I need to do with it.:
-edit- Could I just search for the value in a list of the values and then get the key from that? I know I can use this for finding if the value exists, but I'm pressed for time and need to go do something, so I'll edit it when I can. -/edit-
-edit2- O.O The post took all of my formatting!

-/edit2-
Thanks in advance!
Code:
import pdb
class Basic_Files
#instantiate main variables
phonebook = {}
option = 3
choice = 1
new_name = ""
new_number = ""
look_up_name = ""
loop_up_num = ""
y/n = ""
loop = 1
while loop == 1:
print "Welcome to a basic phone book."
print "Please choose a number:"
print "[1] Add a new name"
print "[2] Find a number"
print "[3] Close the phonebook"
pdb.set_trace()
try:
option = input(">> ")
except KeyboardInterrupt, err:
print "Keyboard input interrupted, Closing,"
loop = 0
else:
if option == 1:
print "Please enter the new name."
new_name = input(">> ")
if phonebook.has_key(new_name):
print "That entry already exists!"
else:
print "Please enter the new number."
new_number = input(">> ")
if phonebook.[b]has_value(new_number)[/b]:
print "This number already exists!"
else:
phonebook [new_name] = new_number
print "Entry complete. Would you like to view it now?"
y/n = input("[y/n] >> ")
if y/n == "y":
print phonebook[new_name]
else:
elif option == 2:
print "Please choose:"
print "[1] Find a name"
print "[2] Find a number"
try:
choice = input(">> ")
except KeyboardInterrupt, err:
print "Keyboard input interrupted, closing."
loop = 0
else:
if choice == 1:
print "Please insert the number:"
try:
look_up_num = input(">> ")
except KeyboardInterrupt, err:
print "Keyboard input interrupted, closing."
loop = 0
else:
if phonebook.[b]has_value(look_up_num):[/b]
print phonebook.[b]key_of(look_up_num)[/b]
elif option == 3:
loop = 0
else:
loop = 1
Edit by smartcat99s: added code tags