[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

On Fri, Feb 14, 2014 at 8:33 AM, Ethan Furman <ethan at stoneleaf.us> wrote: > Oh, it's not that bad! All you have to do is handle the edge case of an > empty string: > > s[::len(s)-1 if s else True] > > *ducks and runs* And the edge case of the one-character string. Also, it's been noted that calling the built-in function len() is slow, so I propose changing that. s[::(sys.getsizeof("\N{MATHEMATICAL BOLD CAPITAL L}"+s)-sys.getsizeof("\N{MATHEMATICAL BOLD CAPITAL E}\N{MATHEMATICAL BOLD CAPITAL N}") or 4)//4] Note the elegance of using the word LEN across two string literals (because string literals are fast) as a means of clearly describing what we are doing - an optimization of the built-in len() function. ChrisA

- Prev by Date:
**Working with the set of real numbers** - Next by Date:
**Working with the set of real numbers** - Previous by thread:
**A curious bit of code...** - Next by thread:
**A curious bit of code...** - Index(es):