Diigo Diary 10/23/2009
HowTo/Sorting – PythonInfo Wiki
Functional Programming HOWTO — Python v3.1.1 documentation
Generators are a special class of functions that simplify the task of writing
iterators. Regular functions compute a value and return it, but generators
return an iterator that returns a stream of values.
When you call a generator function, it doesn’t return a single value; instead it
returns a generator object that supports the iterator protocol. On executing
the yield expression, the generator outputs the value of i, similar to a
return statement. The big difference between yield and a return
statement is that on reaching a yield the generator’s state of execution is
suspended and local variables are preserved. On the next call to the
generator’s .__next__() method, the function will resume executing.
In Python 2.5 there’s a simple way to pass values into a generator.
yield became an expression, returning a value that can be assigned to
a variable or otherwise operated on:
I recommend that you always put parentheses around a yield expression
when you’re doing something with the returned value, as in the above example.
Generators also become coroutines, a more generalized form of subroutines.
Subroutines are entered at one point and exited at another point (the top of the
function, and a return statement), but coroutines can be entered, exited,
and resumed at many different points (the yield statements).
enumerate(iter) counts off the elements in the iterable, returning 2-tuples
containing the count and each element.
>>> for item in enumerate(['subject', 'verb', 'object']):
zip(iterA, iterB, ...) takes one element from each iterable and
returns them in a tuple:
zip(['a', 'b', 'c'], (1, 2, 3)) =>
('a', 1), ('b', 2), ('c', 3)
It doesn’t construct an in-memory list and exhaust all the input iterators
before returning; instead tuples are constructed and returned only if they’re
requested. (The technical term for this behaviour is lazy evaluation.)
eclipse-search-tab – Project Hosting on Google Code
Posted from Diigo. The rest of my favorite links are here.