cannot remove newline from a string
<p>Can you help me with this line of python code? I am trying to add strings to an array, and exclude the newlines. While the code appears to work the first time it splits the string, it seems to think there's another newline in there since it returns an error message: <code>substring not found</code>. However, when i printed the value of cut it returned <code>kdfjsalsdjf</code>, showing the newlines code had been removed</p>

<pre><code>x='lksjdfalkjdsflkajsdfkl\n\nkdfjsalsdjf'

for i in x:
    if i=='\n':
        cut=x.index(i)
        x=x[cut+2:]


Traceback (most recent call last):
  File "&lt;pyshell#5&gt;", line 3, in &lt;module&gt;
    cut=x.index(i)
ValueError: substring not found
</code></pre>

<p>Why don't you use "replace" command?</p>

<pre><code>x.replace("\n","")
</code></pre>

python