sorting a dictionary

Andrew Bennetts andrew-pythonlist at puzzling.org
Tue Feb 4 05:58:51 EST 2003


On Tue, Feb 04, 2003 at 02:31:52AM -0800, Paul Rubin wrote:
> Andrew Bennetts <andrew-pythonlist at puzzling.org> writes:
> > Sure you can... what's wrong with the solution I posted earlier:
> > 
> >     max([(x[1], x[0]) for x in d.items()])[1]
> > 
> > ?
> > 
> > [Besides being a gratuitous one-liner <wink>]
> 
> That uses linear extra storage vs. Alex's which uses constant space.

Fair enough -- but I was more asking why it didn't qualify as O(N).  Alex
later replied to himself to explain that of course it can be done in O(N),
so we're all happy now :)

It's a good point, though... space requirements of algorithms are easily
forgotten.

-Andrew.






More information about the Python-list mailing list