I'm really struggling with this issue, and can't seem to find an answer anywhere.
I've got a text file which has name of the station and location, the task is to print out the names of the stations all underneath each other in order and same for the locations.
In my text file the names of the stations are always made up of two words and the location is 3 words.
text_file = "London Euston 12 London 56, Aylesbury Vale 87 Parkway 99, James Cook 76 University 87, Virginia Water 42 Surrey 78"
Desired outcome would be:
Stations:
London Euston
Aylesbury Vale
James Cook
Virginia Water
Locations:
12 London 56
87 Parkway 99
76 University 87
42 Surrey 78
my current code:
replaced = text_file.replace(","," ")
replaced_split = replaced.split()
i = 0
b = 2
stations = []
locations = []
while b < len(replaced_split):
locations.append(replaced_split[b:b+3])
b += 5
while i < len(replaced_split):
stations.append(replaced_split[i:i+2])
i += 5
for x in range(len(stations)):
print(stations[x])
for y in range(len(locations)):
print(dates[y])
The outcome I'm receiving is printing lists out:
['London', 'Euston']
['Aylesbury', 'Vale']
['James', 'Cook']
['Virginia', 'Water']
['12', 'London', '56']
['87', 'Parkway', '99']
['76', 'University', '87']
['42', 'Surrey', '78']
" ".join()to turn the lists into strings.