Reverses a list or a string.
- Use slice notation to reverse the list or string.
代码实现
def reverse(itr):
return itr[::-1]
使用样例
reverse([1, 2, 3]) # [3, 2, 1]
reverse('snippet') # 'teppins'
Reverses a list or a string.
def reverse(itr):
return itr[::-1]
reverse([1, 2, 3]) # [3, 2, 1]
reverse('snippet') # 'teppins'