-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,065
  • 1
  • 11
  • 27
J.A
  • 192
  • 3
  • 13

3 Answers3

2

As simple as

x = x[::-1]

.......

Aleksandr Borisov
  • 2,042
  • 1
  • 11
  • 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
  • 13,233
  • 12
  • 67
  • 109
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,393
  • 10
  • 17