3 ms·
`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.revers
by wting 14y ago
`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.
- ot 14y agolist 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)