title: How to remove newline characters from csv file
body: <p>I have the below part of code that reads values from the csv file &quot;prom output.csv&quot; and writes them sorted in a new one &quot;sorted output.csv&quot;.</p>
  <pre><code>import collections
  import csv
  
  with open(&quot;prom output.csv&quot;,&quot;r&quot;) as f:
      cr = csv.reader(f,delimiter=&quot;,&quot;)
      d=collections.defaultdict(lambda : list())
      header=next(cr)   
      for r in cr:
          d[r[0]].append(r[1])  
          
  
  with open(&quot;sorted output.csv&quot;,&quot;w&quot;) as f:
      cr = csv.writer(f,delimiter=&quot;,&quot;)
      cr.writerow(header)  
      od = collections.OrderedDict(sorted(d.items()))
      for k,v in od.items():  s
          cr.writerow([k,&quot;,&quot;.join(v)]) 
  </code></pre>
  <p>However the output (see below) has spaces between each line and i would like to remove them. Can anybody help?</p>
  <p><a href="https://i.stack.imgur.com/y6RSD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y6RSD.png" alt="enter image description here" /></a></p>
  <p>The input file &quot;prom output.csv&quot; has no spaces between each line as seen below</p>
  <p><a href="https://i.stack.imgur.com/SpOER.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SpOER.png" alt="enter image description here" /></a></p>
  <p>as a last midification i would like my output to look like:</p>
  <p><a href="https://i.stack.imgur.com/o0igJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o0igJ.png" alt="enter image description here" /></a></p>
  <p>any suggestions?</p>