Код: Выделить всё
exampleInputMap = [
['1', 'a', -1], # do the first action
['2', 'b'], # do the second action
['3', 'h'], # print help
['4', 'q'] # quit the program
]
def mapInputToAction(inputMap, matchFirstCharOnly=True, prompt='> '):
while True:
response = input(prompt)
if len(response) == 0:
for index, row in enumerate(inputMap):
if -1 in row:
return index
else:
for index, row in enumerate(inputMap):
if matchFirstCharOnly:
if response[0] in row:
return index
else:
if response in row:
return index
Подробнее здесь: https://stackoverflow.com/questions/798 ... s-than-thi
Мобильная версия