title: can we trim strings which are already in list? in python
body: <p>here is the sample for string which is inside a list</p>
  <pre><code>item_s=[&quot;hello - this&quot;,&quot;is - a&quot;,&quot;sample - task&quot;,&quot;i&quot;,&quot;want - to&quot;,&quot;do&quot;]
  </code></pre>
  <p>can I have an output like:</p>
  <pre><code>item_s=[&quot;hello-this&quot;,&quot;is-a&quot;,&quot;sample-task&quot;,&quot;i&quot;,&quot;want-to&quot;,&quot;do&quot;]
  </code></pre>
  <p>this is the code i tried to trim the spaces but it was showing error</p>
  <pre><code>amount=list(df[&quot;Price Range&quot;])
  def add_commas(s):
      s1, s2 = s.split('-')
  
  def process(s_part):
      n, tmp_s = len(s_part), []
  
  for i in range(n):
      if i and not i % 3:
          tmp_s.append(',')
      tmp_s.append(s_part[n - i - 1])
  
  return ''.join(tmp_s[::-1])
  
  return process(s1) + '-' + process(s2)
  
  def main():
      amount=list(df[&quot;Price Range&quot;])
  
      return [add_commas(v) for v in amount]
  
  main
  </code></pre>