In article <[EMAIL PROTECTED]>,
Martin Durkin  <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] (Alex Martelli) wrote in
>news:[EMAIL PROTECTED]: 
>>
>> So, something like:
>> 
>> for c in reversed(x): print c
>> 
>> is mostly likely how I'd present the solution to the task. 
>
>This is an interesting point to me. I am just learning Python and
>I wonder how I would know that a built in function already exists?
>At what point do I stop searching for a ready made solution to a
>particular problem and start programming my own function?  Is it just a
>matter of reading *all* the documentation before I start coding?

You should at least know that you can do:

l = list(s)
l.reverse()
for c in l:
    print c

This works in all versions of Python back to 1.5.2 IIRC.  reversed() is
a moderately new built-in function; 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).

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.
-- 
Aahz ([EMAIL PROTECTED])           <*>         http://www.pythoncraft.com/

I support the RKAB
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to