OrderedSet (Python)
Python recipe 576694 by Raymond Hettinger (ordered, set). Revision 9. Set that remembers original insertion order.
View ArticleCompare speeds of different kinds of access to variables (Python)
Python recipe 577834 by Raymond Hettinger (optimization). Revision 5. Compare speeds of locals, nested scopes, global, builtins, instance variables, and class variables.
View ArticleGenerator for permutations, combinations, selections of a sequence (Python)
Python recipe 190465 by Ulrich Hoffmann (algorithms). Permutations and combinations are often required in algorithms that do a complete search of the solution space. They are typically rather large so...
View ArticleFile Tkinter dialogs (Python)
Python recipe 438123 by Sébastien Sauvage . Basic Tkinter dialogs for directory selection, file selection and so on. That's dirt simple (although the official documentation is not very explicit about...
View ArticleRead tabular data from Excel spreadsheets the fast and easy way (Python)
Python recipe 440661 by Nicolas Lehuen (database). Revision 3. Sometimes you get an Excel spreadsheet (say, from the marketing departement) and you want to read tabular data from it (i.e. a line with...
View ArticleDirt simple map/reduce (Python)
Python recipe 577676 by Raymond Hettinger (analysis, crosstab, functional, map_reduce, pivot_table, statistics). Revision 9. Simple tool for analyzing datasets.
View ArticleDependency Injection The Python Way (Python)
Python recipe 413268 by Zoran Isailovski (oop). Revision 9. Sample Pythonic Inversion-of-Control Pseudo-Container.
View ArticleFirst Class Enums in Python (Python)
Python recipe 413486 by Zoran Isailovski (programs). Revision 7. True immutable symbolic enumeration with qualified value access.
View ArticleProof-of-concept for a more space-efficient, faster-looping dictionary (Python)
Python recipe 578375 by Raymond Hettinger (compact, dictionary). Revision 20. Save space and improve iteration speed by moving the hash/key/value entries to a densely packed array keeping only a...
View ArticleBloom Filter (Python)
Python recipe 577684 by Raymond Hettinger (big_table, bloom_filter, sets, spelling_checker, spell_checker). Revision 18. Space efficient, probabilistic set membership tester. Has no False Negatives...
View ArticleReadable switch construction without lambdas or dictionaries (Python)
Python recipe 410692 by Brian Beck (extending). Revision 8. Python's lack of a 'switch' statement has garnered much discussion and even a PEP. The most popular substitute uses dictionaries to map...
View ArticleGroupby (Python)
Python recipe 259173 by Raymond Hettinger (algorithms). Revision 5. Guido inspired SQL-like GROUPBY class that also encapsulates the logic in a Unix-like "sort | uniq".
View ArticleCreating a daemon the Python way (Python)
Python recipe 278731 by Chad J. Schroeder (threads). Revision 6. The Python way to detach a process from the controlling terminal and run it in the background as a daemon.
View ArticleSend an HTML email with embedded image and plain text alternate (Python)
Python recipe 473810 by darrin massena (network). HTML is the method of choice for those wishing to send emails with rich text, layout and graphics. Often it is desirable to embed the graphics within...
View ArticleSingleton? We don't need no stinkin' singleton: the Borg design pattern...
Python recipe 66531 by Alex Martelli (oop). Revision 2. The Singleton design pattern (DP) has a catchy name, but the wrong focus -- on identity rather than on state. The Borg design pattern has all...
View ArticleLinear equations solver in 3 lines (Python)
Python recipe 365013 by Maxim Krikun (programs). Revision 2. Just a little bit of hack: a linear equations solver using eval and built-in complex numbers:>>> solve("x - 2*x + 5*x -...
View ArticleNamed Tuples (Python)
Python recipe 500261 by Raymond Hettinger (shortcuts). Revision 15. Fast, lightweight attribute-style access to tuples.
View ArticleSpreadsheet (Python)
Python recipe 355045 by Raymond Hettinger (programs). Revision 2. Use eval() to drive spreadsheet style logic. The sleeper feature of Py2.4 is the ability to use any object with a mapping interface as...
View ArticleInfix operators (Python)
Python recipe 384122 by Ferdinand Jamitzky (oop). Revision 3. Python has the wonderful "in" operator and it would be nice to have additional infix operator like this. This recipe shows how (almost)...
View ArticleDecorator for BindingConstants at compile time (Python)
Python recipe 277940 by Raymond Hettinger (programs). Revision 9. Decorator for automatic code optimization. If a global is known at compile time, replace it with a constant. Fold tuples of constants...
View Article