Reversing a string

Alex Martelli aleax at mac.com
Wed Jul 4 12:34:57 EDT 2007


Aahz <aahz at pythoncraft.com> wrote:
   ...
> This works in all versions of Python back to 1.5.2 IIRC.  reversed() is
> a moderately new built-in function;

Yep: it came with Python 2.4, first alpha just 4 years ago, final
release about 3 years and 8 months ago.  "Moderately new" seems an
appropriate tag.

> I would agree with people who claim
> that you should memorize most of the built-in functions (which is
> precisely why there is a high barrier to adding more built-in functions).

I think the built-in functions and types a beginner is likely to need
are a "fuzzy subset" (the decision of whether to include or exclude
something being not really obvious:-) roughly including:

abs all any bool chr cmp dict dir enumerate float getattr help hex int
iter len list max min object open ord property raw_input reversed set
sorted str sum tuple unichr unicode xrange zip

all reasonably documented at
<http://docs.python.org/lib/built-in-funcs.html> .  Of course, as I
mentioned, most inclusions and exclusions may be debatable (why do I
think people need xrange and not necessarily range, set and not
necessarily frozenset, property rather than classmethod, hex more likely
than oct, probably not complex, etc etc).


> But certainly if you're using a datatype you should make a point of
> reading all its documentation, which would mean you'd know that list()
> can convert any iterable type.

Yes, and also the methods and operators of (out of the builtin types I
listed above):

dict float int list open[*] set str tuple unicode

[*] well really file, that's the name of the builtin type, but open is
what one should use as a factory function for it!-)

str and unicode have almost identical methods, save for the big crucial
difference on the semantics of method .translate; float and int also
have the same operators; and tuple has hardly anything, so the learning
task is nowhere as big as it may seem from here:-).


Alex



More information about the Python-list mailing list