newbie question!

Jay Dorsey jay at jaydorsey.com
Wed Oct 15 13:42:56 EDT 2003


Brian wrote:
> Hi, im new to python and have a simple question...
> 
> i want too have a list of values - say numbers of tables in a restaurant...
> 1,2,3,4,5. i want to associate a value with each of these numbers... eg. yes
> or no. when a person books table 2, the value corresponding to 2 turns to no
> [not available] etc...
> 
> what would be the best way to do this ? a little code help would help aswell
> !!! - newbie

You could use a dictionary to hold the information:

 >>> tables = {}
 >>> for i in range(1, 11):
...	tables[i] = "no"
...
 >>> tables[2] = "yes"
 >>> for table in tables:
...     print "%2d   : %s" % (table, tables[table])
...
  1    : no
  2    : no
  3    : no
  4    : no
  5    : no
  6    : no
  7    : no
  8    : no
  9    : no
10    : no


Jay






More information about the Python-list mailing list