Thanks to all. I didn't know enumerate() and would use it. Amit
Beni Cherniavsky wrote: > On Tue, Jun 23, 2009 at 11:19, Amit Dor-Shifer<[email protected]> wrote: > >> Hi. >> Is there some common implementation in python for displaying to user an >> enumerated list of items, and then prompt her to select one by >> selecting the item's number? >> >> > Sounds simple enough to roll your own: > > def prompt_choice(items): > for n, item in enumerate(items): > print '[%s] %s' % (n + 1, item) > while True: > response = raw_input("Please select 1..%s and press Enter: " % (n + > 1)) > if response.isdigit(): > choice = int(response) - 1 > if 0 <= choice < n + 1: > return items[choice] > >
_______________________________________________ Python-il mailing list [email protected] http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
