Python tricks

Ben Finney bignose+hates-spam at benfinney.id.au
Mon Jan 12 08:37:51 EST 2009


RajNewbie <raj.indian.08 at gmail.com> writes:

> Could someone chip in with other suggestions?

Set up an iterable that will end under the right conditions. Then,
iterate over that with ‘for foo in that_iterable’. This idiom is
usually far more expressive than any tricks with ‘while’ loops and
‘break’ statements.

For tools to work with that can give you such an iterable without
needing to make one from scratch, try the following and use the one
that is most suitable to the problem at hand:

* list
* dict
* list comprehension
* generator expression
* generator function
* functions from the ‘itertools’ module

-- 
 \                   “Too many Indians spoil the golden egg.” —Sir Joh |
  `\                                                   Bjelke-Petersen |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list