[Tutor] Am I making this harder than it needs to be?

Pujo Aji ajikoe at gmail.com
Wed May 25 15:47:56 CEST 2005


try this code:
    L = [(1,11),(2,22)]
    print max(L)
    print min(L)

I don't know if that what you want.

good luck
pujo

On 5/25/05, Ron Phillips <RPhillips at engineer.co.summit.oh.us> wrote:
>  
> short version: I  need a way to get max and min E and N out of
> [(E0,N0),(E1,N1)...(En,Nn)] without reordering the list 
>   
> long version: 
>   
> I would like a list of geographic coordinates (Easting, Northing) to
> maintain a "bounding box"
> [(minEasting,minNorthing),(maxEasting,maxNorthing)]
> attribute. 
>   
> I did it like this: 
>   
> class geoCoordinateList(UserList):
>     def __init__(self):
>         UserList.__init__(self)
>         self.boundingBox = geoBox(minEN=geoCoordinate(),
>                                   maxEN=geoCoordinate())
>  
>     def append(self, geoCoord):
>         self.extend([geoCoord])
>         self.boundingBox.challenge(geoCoord)#bumps the max and min if
> necessary
>  
> but I'd have to override almost all the UserList methods, unless there's a
> way to call boundingBox.challenge() on any change to the list. 
>   
> The other way I thought would be to make a getBB method, like: 
>   
>     def getBB(self):
>         new=geoBox()
>         for gC in self:
>             new.challenge(gC)#bumps the corners if needed 
>         self.boundingBox=new
>         return(new)
>  
> but that seems like a lot of churning if nothing has changed. 
>   
> I suspect there's some slick, readable way to do this, and when I see it
> I'll say "Doh!" 
>   
>   
>   
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
>


More information about the Tutor mailing list