title: how to use 'map' function to remove the last character from a line and then splits it at the commas
body: <pre><code>def map(fn, seq):
      res = []
  
      for ele in seq:
          res.append(fn(ele))
      return res
  </code></pre>
  
  <p>Task: By using the above <code>map</code> function, write a <code>read_route_data</code> function that removes the last character from a line, (<code>'/n'</code>), and then splits the line at the commas. The result of <code>read_route_data</code> should be a <code>list</code> of tuples, with each <code>tuple</code> containing 4 datas:</p>
  
  <p>For example: a list of the first 3 tuples should look like this: </p>
  
  <pre><code>&gt;&gt;&gt; bus_stations = read_route_data(’smrt_routes.txt’)
  &gt;&gt;&gt; bus_stations[:3]:
  [(’106’, ’1’, ’1’, ’43009’), (’106’, ’1’, ’2’, ’43179’), (’106’, ’1’, ’3’, ’43189’)]
  </code></pre>
  
  <p>This is my code: </p>
  
  <pre><code>def read_route_data(filename):
      with open(filename, 'r') as f:
          lines = list(f)
    return map(lambda x: x.split(), lines)
  </code></pre>
  
  <p>Am I on the right track? I didn't manage to get a <code>list</code> of <code>tuple</code> but instead my output is:</p>
  
  <pre><code>[['106,1,1,43009'], ['106,1,2,43179'], ['106,1,3,43189']]
  </code></pre>