On Mon, 15 Oct 2007 14:47:30 +0200, Francesco Guerrieri wrote: >> def myreversed(sequence): >> if isinstance(sequence, basestring): >> return type(sequence)().join(reversed(sequence)) >> else: >> return type(sequence)(reversed(sequence)) >> >> (in fact, that's so simple I wonder why the built-in reversed() doesn't >> do that). > > simple: > In the face of ambiguity, refuse the temptation to guess.
What ambiguity? What guess? The above is completely unambiguous: it returns a sequence of the same type as the input. It doesn't support xrange objects, but that's not really a great loss. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list