Nov-19-2019, 02:51 AM
Doing that will be a bit more complicated than the code that you currently have. I'll write and explain the code for you.
def main(): mycities = ['Cape Girardeau,MO,63780','Columbia,MO,65201', 'Kansas City,MO,64108','Rolla,MO,65402', 'Springfield,MO,65897','St Joseph,MO,64504', 'St Louis,MO,63111', 'Ames,IA,50010', 'Enid,OK,73773', 'West Palm Beach,FL,33412', 'International Falls,MN,56649', 'Frostbite Falls,MN,56650' ] formattedCities = [] comparisonCities = [] for city in mycities: formattedCities.append(city.split(',')) #Each city is put in a list, and in that list, everything that was seperated by a comma, got split into different strings comparisonCities.append(city.split(',')[0]) #The same thing here, but instead of keeping the list, the code just grabs the first string of the list, or the name part. longestString = len(max(mycities)) #This is a number representing how many character long, the longest name is # Print the table for c in formattedCities: print(c[0] + ' '*(longestString - len(c[0]) + 1) + '%s %s' %(c[1], c[2])) #The "c[0]" prints the first elements of the script, the name, then the spaces are calculated using the longest character length compared to the length of the name currently being printed. The plus one is for to make sure a space is printed when printing the longest name. Finally, the last two elements of the list, the state abbreviation and zip code, are printed separated by space main()I hope you understand everything.