#NEWLINE# def prompt_with_options( prompt , options , default ) : #NEWLINE# #INDENT# "Return the user's choice from the list of option lists.\n\n    The first option from each list is chosen as the hint for that option,\n\n    for example:\n        prompt_with_options('do it', [['yes', 'y'], ['no', 'n']], None)\n\n    will prompt with:\n        'do it [yes/no]? '\n\n    Note that the choice is converted to lowercase before comparison so all\n    choices should be in lowercase.\n\n    Loop until one of the supplied options is chosen.\n\n    :prompt: the string to present to the user\n    :options: the list of option string lists\n    :default: the string default option or None if there is no default\n\n    " #NEWLINE# lead_options = [ o [ 0 ] for o in options ] #NEWLINE# if ( default is not None ) : #NEWLINE# #INDENT# assert ( default in lead_options ) #NEWLINE# lead_options = map ( ( lambda x : ( x . upper ( ) if ( x == default ) else x ) ) , lead_options ) #NEWLINE# #UNINDENT# hint = '[{}]' . format ( '/' . join ( lead_options ) ) #NEWLINE# while True : #NEWLINE# #INDENT# print ( '{} {}' . format ( prompt , hint ) , end = ' ' ) #NEWLINE# choice = raw_input ( ) . lower ( ) #NEWLINE# if ( ( default is not None ) and ( choice == '' ) ) : #NEWLINE# #INDENT# choice = default #NEWLINE# #UNINDENT# for option_list in options : #NEWLINE# #INDENT# if ( choice in option_list ) : #NEWLINE# #INDENT# return option_list #NEWLINE# #UNINDENT# #UNINDENT# print ( 'Please choose from:' ) #NEWLINE# for option_list in options : #NEWLINE# #INDENT# print ( '  {}' . format ( ' or ' . join ( option_list ) ) ) #NEWLINE# #UNINDENT# print ( )