2
Seq = []
Head = []

for line in range (0, len(text)):
   if line in '>':
      Head.append(line)
   else:
      Seq.append(line)

I am trying to append the header of FASTA sequences and the nucleotide sequence and separate them on a list. I don't know how to say that if line has '>', add to Head, else add to Seq

  • 2
    You're on the right track with [the ```in``` operator.](https://stackoverflow.com/a/3437070/792238). Might need to flip the if condition. – Siddhartha Oct 02 '18 at 03:50
  • 2
    To test if `'>'` is in the text use: `'>' in text`. For example: `if '>' in text: ...` – RobertL Oct 02 '18 at 03:57

1 Answers1

1

The line: line in '>' is testing whether line can be found inside the string '>'. You need to swap them around to '>' in line. This will test if the string '>' can be found inside line. If you are trying t test if the first character of line is '>', use 'line[0] == '>'.

Also when using range the start will default to zero so you could say for x in range(len(text))

Final code:

Seq = []
Head = []

for line in range (len(text)):
   if '>' in line:
      Head.append(line)
   else:
      Seq.append(line)
Joyal Mathew
  • 614
  • 7
  • 24