[Tutor] Lambda function, was: Simple counter to determine frequencies of words in adocument
ALAN GAULD
alan.gauld at btinternet.com
Wed Nov 24 19:58:10 CET 2010
> > Notice that it uses key as a function inside sorted.
> > And lambda creates a function so sorted applies
> > the lambda to each item in turn to retrieve the sort key.
>
> OK. I get it. Thanks a lot. This should have been clear if I had been
> able to see the code for the sorted() method.
OK Good, But I stress the code I posted bears no relation to
the actual code for sorted! It was purely illustrative.
> Can anyone point me to a URL (or some other document)
> where the code for the different built-in methods can be examined?
The source code for Python, including all the standard modules
and the builtin stuff is available on the web site to view or download.
(The joy of Opensource.) Much of the core code (like sorted) is
actually written in C but many of the higher level modules are in
Python - and you probably have it on your PC/Mac if you look
for the Python modules folder...
The good news is that unlike some opensource projects the code
quality is pretty good and you can usually figure out how it works
fairly easily, even the C stuff. (Having said that I only look at the
source about once a year on average, only if things are getting
really hairy... :-)
HTH,
Alan G.
More information about the Tutor
mailing list