0

I'm new on the platform:

I have a doubt about the use of the replace command.

Here is my code and what I need to do: The thing is that I need to replace a substring with a string sequence.

For example: from: Hitacoworld to Hiworld. The thing is that I part from a dictionary with the string and substrings and I don't know how to get the string without the substring part. I use the command replace this way:

ntdna = ''

ntdna += string.replace(seqs[element],'',)

Where 'string' is my string and 'seqs[element]' are the substrings that I want to remove from the string, but the problem is that when I see the outcome I'm not getting the right string, so I think the problem is in the use of the replace, any hint or something I could use? Ty in advance, I'm lost.

enter image description here

Inazense
  • 1,517
  • 3
  • 18
  • 28
dananada
  • 21
  • 2
  • You want this string to get smaller and smaller as it matches more subsequences, right? So why do you built `ntdna` as a new variable? Why don't you just keep reducing `string`, as in `string = string.replace(seqs[element,''))`? And please delete the `from os import replace` line. That `replace` is a file rename function. It has nothing to do with strings. – Tim Roberts Jun 26 '21 at 18:44
  • @TimRoberts ty so much, editing that maked the code work, and the replace thing was written itself when I write replace, i didn't even notice that – dananada Jun 26 '21 at 18:48

0 Answers0