I have a bunch of lists and I want to inverse their string content from left to right.
How to transform x
x = ['TARDBP', 'BUB3', 'TOP2A', 'SYNCRIP', 'KPNB1']
to
x = ['KPNB1', 'SYNCRIP', 'TOP2A', 'BUB3', 'TARDBP']
I have a bunch of lists and I want to inverse their string content from left to right.
How to transform x
x = ['TARDBP', 'BUB3', 'TOP2A', 'SYNCRIP', 'KPNB1']
to
x = ['KPNB1', 'SYNCRIP', 'TOP2A', 'BUB3', 'TARDBP']
You can do something like this:
x = x[::-1]
or this:
x = list(reversed(x))
You can also perform an in-place reverse as follows:
x.reverse()
def reverse(L):
if L == []:
return []
else:
return reverse(L[1:]) + [L[0]]
print(['TARDBP', 'BUB3', 'TOP2A', 'SYNCRIP', 'KPNB1'])
print(reverse(['TARDBP', 'BUB3', 'TOP2A', 'SYNCRIP', 'KPNB1']))