I have this code below to show a list of options that user can choose entering a number.
It is working fine but I don't understand why the options don't appear ordered.
Instead of having:
1 - User Management
2 - Uploads
8 - Exit
I'm having:
1 - User Management
8 - Exit
2 - Uploads
Do you see where the issue is?
Choice = namedtuple("Choice", ['msg', 'callback'])
def nav():
print ""
while True:
response_options = {'1': Choice(msg="User Management", callback=userManagment),
'2': Choice(msg="Uploads", callback=upload),
'8': Choice(msg="Exit", callback=sys.exit)}
result = make_choice(response_options)
if result is None:
print "-> Selected option not available."
print ""
else:
result.callback()
return False
def make_choice(optiontable):
for resp, choiceobj in optiontable.items():
print("{} - {}".format(resp, choiceobj.msg))
print ""
print "Select an option: "
print ""
usr_resp = raw_input(">> ")
print ""
return optiontable.get(usr_resp, None)