problem with global var

Bruno Ferreira brunoacf at gmail.com
Fri Jan 4 07:31:55 EST 2008


Hello all,

Amazing :)

The program is working properly now,  the code is much better and I
learned a bit more Python.

Thank  you all, guys.

Bruno.

2008/1/4, Peter Otten <__peter__ at web.de>:
> Bruno Ferreira wrote:
>
> > I wrote a very simple python program to generate a sorted list of
> > lines from a squid access log file.
>
> Now that your immediate problem is solved it's time to look at the heapq
> module. It solves the problem of finding the N largest items in a list
> much more efficiently. I think the following does the same as your code:
>
> import heapq
>
> def key(record):
>     return int(record[4])
>
> logfile = open("squid_access.log", "r")
> records = (line.split() for line in logfile)
> topsquid = heapq.nlargest(50, records, key=key)
>
> for record in topsquid:
>     print record[4]
>
> Peter
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list