On Thu, Jul 28, 2011 at 2:47 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On Thu, Jul 28, 2011 at 2:44 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote: >> path = '/home/gyoung/hacks/pathhack/foo.py' >> parts = [part for path, part in iter(lambda: os.path.split(path), ('/', ''))] >> parts.reverse() >> print parts >> >> But that's horrendously ugly. Just write a generator with a while >> loop or something. > > Also, note that if the path does not start with '/', the result will > be an infinite loop.
Oh, and this won't work at all in Python 3, because it relies on the lambda having access to the list comprehension scope. -- http://mail.python.org/mailman/listinfo/python-list