![](https://secure.gravatar.com/avatar/e79e2064f0ec68a0493ca5de758aeaa4.jpg?s=120&d=mm&r=g)
Feb. 2, 2004
6:57 p.m.
[Jewett, Jim J]
... The most obvious use case is to generate unique keys (as lisp gensym).
Just noting a practical hack that's often sufficient: import sys genunique = iter(xrange(sys.maxint)).next Then each call to genunique() delivers "the next" (short) integer, and it inherits thread safety from the global interpreter lock. A similar effect can be gotten via import itertools genunique = itertools.count().next and that also inherits thread safety from the GIL. A difference is that the xrange spelling stops when it reaches sys.maxint, but the .count spelling silently wraps around to -sys.maxint-1 then (undetected overflow at the C level).