two little syntax questions

Doug Fort doug.fort at verizon.net
Thu Aug 30 14:53:48 CEST 2001


Marcus Stojek wrote:

> Hi,
> 
> Two little syntax questions:
> 1.-----------------------------
> I have a huge dict of 3-tuples. I need the min and max value
> of all tuple[0] entries.
> 
> I would like to use reduce. Something like:
> 
> nodes[1]=(3,2,5)
> nodes[2]=(-1,2,9)
> nodes[3]=(0,1,6)
> nodes[4]=(2,9,1)
> 
> minx = reduce(lambda a,b:min(a,b),nodes???and now what)
> 

How about just 

minx = min(nodes.values())[0]

i.e tuple[0] of the minimum tuple?


> how do I explain: take first entry in tuple for all keyvalues
> 2.------------------------------
> 
> I have to print the remaining entries of a list
> (first entries are printed in groups of 8 per line)
> 
> lines = len(list)/8
> rest = len(list)%8
> print rest * "i," % (list[lines*8:])
> 

print rest % "%i, " % tuple(list[lines*8:])

This will work, but I'm sure there is a more elegant way to do it. It might 
be in the Python Cookbook.

> doesn't work. Okay I know print is expecting a tuple and
> list[lines*8:] is not. So how can I transform this into
> a tuple.
> 
> Thanks a lot
> Marcus
> 
> 
> 
> 
> 
> 
> 
> 

-- 
Doug Fort <dougfort at dougfort.net>
http://www.dougfort.net

______________________________________________________________________
Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.uncensored-news.com
   With Seven Servers In California And Texas - The Worlds Uncensored News Source
  



More information about the Python-list mailing list