What Is New in Python 1.1
Python 1.1 added several important features including callable objects, lambda expressions, map(), filter(), reduce() built-ins, and significant improvements to the class system and module handling. It brought Python closer to a complete functional and object-oriented language.
| Category | Change | Notes |
|---|---|---|
| Language | lambda -- anonymous function expressions |
Borrowed from Lisp/Scheme |
| Builtins | map(), filter(), reduce() built-in functions |
Functional programming primitives |
| Language | __call__ -- callable objects |
Objects that behave like functions |
| Language | Improved class and instance __dict__ access |
Better introspection |
| Standard Library | Improved os module for operating system interfaces |
More complete POSIX coverage |
| Standard Library | Early tkinter (then called Tkinter) for GUI programming |
GUI toolkit wrapper for Tcl/Tk |
Key Additions in Python 1.1
lambda -- Anonymous Functions
lambda creates a small anonymous function inline. It is limited to a single expression -- no statements allowed, no multi-line bodies. In Python 1.1, lambda was the primary way to pass a simple function to map(), filter(), or sorted()-like calls before list comprehensions or generator expressions existed.
double = lambda x: x * 2
square = lambda x: x ** 2
print(double(5)) # 10
print(square(4)) # 16
# Used with map/filter:
numbers = [1, 2, 3, 4, 5, 6]
evens = list(filter(lambda x: x % 2 == 0, numbers))
doubled = list(map(lambda x: x * 2, numbers))
In modern Python, list comprehensions and generator expressions are preferred over map()/filter() with lambdas for readability. Lambdas remain useful as callbacks in GUI code, sorting keys, and functional-style pipelines.
map(), filter(), reduce()
These three higher-order functions, borrowed from functional programming, apply a function to every element of an iterable, select elements matching a predicate, and fold a sequence to a single value, respectively.
from functools import reduce # in Python 3, reduce moved to functools
nums = [1, 2, 3, 4, 5]
doubled = list(map(lambda x: x * 2, nums)) # [2, 4, 6, 8, 10]
evens = list(filter(lambda x: x % 2 == 0, nums)) # [2, 4]
total = reduce(lambda acc, x: acc + x, nums) # 15
Callable Objects via __call__
Implementing __call__ on a class makes instances callable like functions. This pattern is used for stateful callables -- objects that behave like functions but carry configuration or accumulated state.
class Multiplier:
def __init__(self, factor):
self.factor = factor
def __call__(self, value):
return value * self.factor
triple = Multiplier(3)
print(triple(10)) # 30
print(callable(triple)) # True
FAQ
When should lambda be used vs a def?
Use lambda only for short, single-expression functions used inline where defining a named function would be unnecessarily verbose -- primarily as sort keys (sorted(items, key=lambda x: x.date)) and simple callbacks. Use def for anything that has a name, is reused, needs a docstring, or contains logic beyond a single expression.
Is reduce() considered Pythonic?
Not particularly. Guido van Rossum has expressed the view that explicit loops are clearer than reduce() for most cases, which is why it was moved to functools in Python 3. The exception is for well-known patterns like sum, product, or boolean any/all -- but Python has dedicated built-ins (sum(), any(), all()) for those. reduce() is best for custom fold operations with a binary function.
What is a practical use case for __call__?
Decorators are one common use: a class-based decorator stores configuration in __init__ and implements the wrapping logic in __call__. Other cases: memoization objects, partially-applied functions before functools.partial existed, and callable strategy objects in design patterns.
Why was Tkinter the main GUI toolkit for early Python?
Tcl/Tk was one of the few cross-platform GUI toolkits available in the early 1990s. Guido had experience with it, and wrapping it in Python (originally as Tkinter) was a natural choice. It remains in the stdlib today as tkinter. Alternatives like PyQt, wxPython, and later Kivy require separate installation.
Were lambda and functional features inspired by specific language?
Yes -- primarily Lisp and Scheme. Guido van Rossum has noted that Python's lambda, map, filter, and reduce were borrowed from functional programming traditions. He later expressed some regret about adding them, feeling that list comprehensions (Python 2.0) are a more Pythonic alternative that renders most uses of map/filter with lambdas unnecessary.