Martin Durkin wrote: > Duncan Booth <[EMAIL PROTECTED]> wrote in > news:[EMAIL PROTECTED]: > >> Martin Durkin <[EMAIL PROTECTED]> wrote: >> >>>>>>> def rev(x): >>>> mylist = [] >>>> for char in x: >>>> mylist.append(char) >>>> mylist.reverse() >>>> for letter in mylist: >>>> print letter >>>> >>>> However, compare the incredible difference in clarity and elegance >>>> between that and: >>>> >>>>>>>> print "\n".join("spam"[::-1]) >>> OK, maybe I'm missing the point here as I'm new to Python. The first >>> one seems clearer to me. What am I missing? >>> >> I think all you are missing is familarity with Python, but I too don't >> like one-liners simply for their own sake. >> > > I guess that's it. The first one reads more like a textbook example which > is about where I am at. Is there any speed benefit from the one liner?
Almost definitely. But you can check yourself by using the timeit module. Stefan -- http://mail.python.org/mailman/listinfo/python-list