0

I have a string "ATCGATCG" and I want it to be reversed so its "GCTAGTCA". I thought about using:

data_r2[total:]+s[0] 

Where total is the result from a counting script I have which will count the number of characters in the string. I realise that this will rotate the string and just end up with the same order if totally rotated which isn't what I want at all.

Does anyone know how to do this so it is the input string reversed so the right most character is now the left most character etc?

Ffisegydd
  • 51,807
  • 15
  • 147
  • 125
thh32
  • 77
  • 2
  • 8

2 Answers2

1
"ATCGATCG"[::-1] == "GCTAGCTA"

This uses slice notation, from the start to the end stepping by negative one.

Adam Smith
  • 52,157
  • 12
  • 73
  • 112
  • 1
    It's also probably a million different duplicates on SO :) – Adam Smith May 02 '14 at 16:33
  • This doesn't produce the OP's desired output. He could have made a typo though... –  May 02 '14 at 16:33
  • @iCodez ha I didn't actually read the desired output! I'm assuming that MUST be a typo. If not, please let me know OP and further clarify your question – Adam Smith May 02 '14 at 16:34
  • Yeah it was a typo, as I said I wanted to reverse the string which this does so thank you so much for this. – thh32 May 02 '14 at 19:22
0

Alternative but slower way.

In [2]: s="ATCGATCG"

In [3]: ''.join(reversed(s))
Out[3]: 'GCTAGCTA'
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321