I have a problem that I have been working on. I felt like I was getting close just to find out with wasn't the 100% correct way of doing it. What I need to do is take a list of names from a file in the format last, first, middle. Here is one way I tried to do it.
The names in the txt file are listed as:
Neuman, Alfred E.
Stevenson, Robert Lewis
Bush, George Herbert Walker
Edit: It doesn't show, but there are 3 spaces in between Herbert and Walker
names = open("Names.txt", 'rU') for name in names: s = name.split(",") newNames=s.strip() +" "+ s.strip() print newNames
When I print it, the output is:
Alfred E. Neuman
Robert Lewis Stevenson
George Herbert Walker Bush
Edit: Also still 3 spaces between Herbert and Walker
It looks alright except I need to make it so the whitespace between 'Herbert' and 'Walker' is just a single space. Also it needs to be able to handle even more middle names. I was told to perhaps not split it at the "," which makes sense. I'm just not sure what to do from there.
Edited by python-noob: spaces didnt show up