title: stripping space between string in convert to list
body: <p>I have a string - data is read from *.txt</p>
  
  <pre><code>21 197 251 251 253 107 0 0 0 0 0
  </code></pre>
  
  <p>want to convert to the list as follows : </p>
  
  <pre><code>[21.0, 197.0, 251.0, 251.0, 253.0, 107.0, 0, 0, 0, 0, 0]
  </code></pre>
  
  <p>wrote this function and tried options #1, #2, and #3 </p>
  
  <pre><code>def loadCsv(filename):
      lines = csv.reader(open(filename, "rb"))
      dataset = list(lines)
      for i in range(len(dataset)):
          #1 dataset[i] = [float(x) for x in dataset[i]]
          #2 dataset[i] = [map(float, x.strip()) for x in dataset[i]]
          #3 dataset[i]=[map(float, x.split()) for x in dataset[i]]
      return datase
  </code></pre>
  
  <p>When I use: </p>
  
  <ol>
  <li>the string obviously cannot be converted to float, </li>
  </ol>
  
  <blockquote>
    <p>Error I receive ValueError: invalid literal for float()</p>
  </blockquote>
  
  <ol start="2">
  <li>I thought there is a space between the elements that's causing it. </li>
  </ol>
  
  <blockquote>
    <p>ValueError: could not convert string to float: there is space that is
    causing that error</p>
  </blockquote>
  
  <ol start="3">
  <li>When I map string to float using this, it works on this function, but then when I call the data to categorize, it renders </li>
  </ol>
  
  <blockquote>
    <p>unhashable list error</p>
  </blockquote>
  
  <pre><code>def separateByClass(dataset):
      separated = {}
      for i in range(len(dataset)):
          vector = dataset[i]
          if (vector[-1] not in separated):
              separated[vector[-1]] = []
          separated[vector[-1]].append(vector)
      return separated
  </code></pre>
  
  <p>Any thoughts? </p>
  
  <hr>
  
  <blockquote>
    <p>I am updating loadCsv function as below which resolved the issue:</p>
  </blockquote>
  
  <hr>
  
  <pre><code>def loadCsv(filename):
      lines = open(filename)
      lines=lines.read()
      dataset = list(lines.split())#list(lines)
  
      for i in range(len(dataset)):
  
          #dataset[i] = [float(x) for x in dataset[i]]
          #dataset[i]=[map(float, x.strip()) for x in dataset[i]]
          dataset[i]=[float(x) for x in dataset[i]]
      return dataset
  </code></pre>