FW: [Python-checkins] python/dist/src/Doc/whatsnew whatsnew24.tex, 1.5, 1.6

It would be nice to present the new features in light of what makes them desirable. "for elem in reversed(mylist)" wins in readability, speed, and memory performance over "mylist.reverse(); for elem in mylist" or "for elem in mylist[::-1]". The readability win is predicated on the notion that half-open intervals are easier to understand in the forwards direction. 'xrange(n//2, 0, -1)' is not as instantly understandable as reversed(xrange(1, n//2)). Using the newer form, anyone can quickly identify the first element, last element, and number of steps.
The keys points here are that 1) any iterable may be used as an input and 2) list.sorted() is an in-line expression which allows it to be used in function arguments, lambda expressions, list comprehensions, and for-loop specifications: genTodoList(today, list.sorted(tasks, key=prioritize)) getlargest = lambda x: list.sorted(x)[-1] x = [myfunc(v) for v in list.sorted(mydict.itervalues())] for key in list.sorted(mydict): . . .
+ \item The \module{heapq} module is no longer implemented in Python, + having been converted into C.
And it now runs about 10 times faster which makes it viable for industrial strength applications.
\item The \module{random} module has a new method called \method{getrandbits(N)}
Formerly, there was no O(n) method for generating large random numbers. The new method supports random.randrange() that arbitrarily large numbers can be generated (important for public key cryptography and prime number generation).
participants (1)
-
Raymond Hettinger