title: Formatting Last Name, First Name
body: <p>I'm doing this Project to extract data from an external .txt file containing 'employee names' and 'monthly sales data'. The format of the text file (complete file: is 'string' followed by 12 instances of floats)</p>
  
  <pre><code>last name, first name
  45
  23
  34
  ....
  last name2, first name2
  78
  32
  23
  ....
  </code></pre>
  
  <p>My program is almost complete, but I need to format the 'last name, first name' to 'first name, last name' while printing the results. Here is the code of that part so you get a better idea. I'm using 'dict()' and .iteritems() to go through the 7 employees and their respective 12 month sales in the original file:</p>
  
  <pre><code>data = {} # dict: list of all values for person by person name
  with open("SalesData.txt", "rt") as f:
      data_key = f.readline() # We remember first line (first man)
      data[data_key] = [] # empty list of values
      for line in f:
          # then we suppose every line is float.
          try:                             
              # convert to float
              value = float(line.strip())  
              # add to data
              data[data_key].append(value)
              # If it does not convert, then it is next person
          except ValueError: 
              # next person's name
              data_key = line
              # new list
             data[data_key] = []
  for employee, stats in data.iteritems():
      print employee
  </code></pre>
  
  <p>Please note that 'employee' is stored as 'last name, first name' and I want to just switch it and get rid of the ','.</p>
  
  <p>Any help will be greatly appreciated! I just started working with the dict() and sometimes I find it difficult to manipulate the data.</p>
  
  <p><em>UPDATE</em>
  The main issues is not the actual formatting. This is what happens:
  I used to after gather the data, format the 'last name, first name'</p>
  
  <pre><code>print ' '.join(employee.split(',')[::-1]).strip()
  </code></pre>
  
  <p>This work, but the result is printed in exactly this manner:</p>
  
  <pre><code>Shelly (first name)
   Adams (last name -also notice the blank space before Adams)
  </code></pre>