Skip to content

Instantly share code, notes, and snippets.

@beltiras
Forked from gunnarig/pypp.py
Last active October 11, 2018 18:18
Show Gist options
  • Save beltiras/82d2c81c0a335b72cdd1931ccb218dd3 to your computer and use it in GitHub Desktop.
Save beltiras/82d2c81c0a335b72cdd1931ccb218dd3 to your computer and use it in GitHub Desktop.
def menu_selection():
try:
print("Menu:")
choice = str(input("add(a), remove(r), find(f):" )).lower
except ValueError:
print("please follow the directions above")
return choice
def execute_selection(choice, a_dict):
if choice == "a":
add_to_dict(a_dict)
return a_dict
elif choice == "r":
remove_from_dict(a_dict)
return a_dict
elif choice == "f":
find_key(a_dict)
return a_dict
def add_to_dict(a_dict):
add_key = input("Key:" )
add_value = input("Value:" )
a_dict[add_key] = add_value
return a_dict
#def remove_from_dict(a_dict):
#remove_key = input("Key to remove:" )
def find_key(a_dict):
find = input("Key to locate" )
if find in a_dict:
print(find, value )
else:
print("Not found")
return a_dict
# Do not change this main function
def main():
more = True
a_dict = {}
while more:
choice = menu_selection()
execute_selection(choice, a_dict)
again = input("More (y/n)? ")
more = again.lower() == 'y'
dictlist = dict_to_tuples(a_dict)
print(sorted(dictlist))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment