I defined a function, which could swap the elements in the string. When I used the swapx function twice, there is an error. Here is my code.
def swapx(lst):
helper=lst[0]
lst[0]=lst[-1]
lst[-1]=helper
s=list("python")
swapx(s)
print(s)
swapx(swapx(s))
['n', 'y', 't', 'h', 'o', 'p']
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-100-f89e12aa1f31> in <module>
7 swapx(s)
8 print(s)
----> 9 swapx(swapx(s))
<ipython-input-100-f89e12aa1f31> in swapx(lst)
1 def swapx(lst):
----> 2 helper=lst[0]
3 lst[0]=lst[-1]
4 lst[-1]=helper
5
TypeError: 'NoneType' object is not subscriptable