Help understanding the decisions *behind* python?
inky788 at gmail.com
Fri Jul 24 17:07:30 CEST 2009
On Jul 23, 3:42 am, Hendrik van Rooyen <hend... at microcorp.co.za>
> On Wednesday 22 July 2009 16:36:51 Inky 788 wrote:
> > On Jul 22, 2:36 am, Hendrik van Rooyen <hend... at microcorp.co.za>
> > wrote:
> > > The good reason is the immutability, which lets you use
> > > a tuple as a dict key.
> > Thanks for the reply Hendrik (and Steven (other reply)). Perhaps I'm
> > just not sophisticated enough, but I've never wanted to use a list/
> > tuple as a dict key. This sounds like obscure usage, and a bit
> > contrived as a reason for having *both* lists and tuples.
> Steven showed why you cannot have a mutable thing
> as a key in a dict.
> if you think it is contrived, then please consider how you would
> keep track of say the colour of a pixel on a screen at position
> (x,y) - this is about the simplest "natural" tuple format and
My guess is that this is probably the way most people do it:
if len( sys.argv ) != 3:
print "Please pass exactly 2 ints. Exiting."
NUM_COLUMNS = int( sys.argv )
NUM_ROWS = int( sys.argv )
print "Making array of %s columns by %s rows." % (NUM_COLUMNS,
return int( 255 * random.random())
# red green blue
return [rand(), rand(), rand()]
temp_row = 
for i in range(num_columns):
temp_row.append( make_a_pixel() )
def make_array_of_pixels(num_columns, num_rows):
rows = 
for i in range(num_rows):
rows.append( make_a_row(num_columns) )
for row in pixel_array:
for pixel in row:
print pixel, ' ',
rows_of_pixels = make_array_of_pixels(NUM_COLUMNS, NUM_ROWS)
More information about the Python-list