Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

`reversed(s)` returns an iterator. The much slower equivalent of `s[::-1]` is `''.join(reversed(s))`.

It's odd how Python has list.reverse() but not str.reverse(). Probably a conscious design decision sometime ago.



list is mutable while str is not. So reverse() should return a new copy, but it would duplicate the functionality of s[::-1] (which is quite idiomatic, although a bit obscure)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: