-1

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']
achref
  • 1,150
  • 1
  • 12
  • 28
J.A
  • 204
  • 1
  • 4
  • 13

3 Answers3

2

As simple as

x = x[::-1]

.......

Aleksandr Borisov
  • 2,136
  • 1
  • 13
  • 14
2

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() 
Mohamed Ali JAMAOUI
  • 14,275
  • 14
  • 73
  • 117
0
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']))
englealuze
  • 1,445
  • 12
  • 19