Grant Edwards wrote:
I recently ran across this construct for grabbing the last (whitespace delimited) word in a string: s.rsplit(None,1)[1] ... I've always done this: s.split()[-1] I was wondering what the advantage of the rsplit(None,1)[1] approach would be ...
Others have pointed out the efficiency reason (asking the machine to do a pile of work that you intend to throw away). But nobody warned you: s.rsplit(None, 1)[-1] would be better in the case of 'single_word'.rsplit(None, 1)
--Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list