Question: In this programming task, you'll write a simple Python script to read a file a process the data contained in the file. Throughout the programming

In this programming task, you'll write a simple Python script to read a file a process the
data contained in the file.
Throughout the programming aspect of the unit, numerous files will be provided, each
requiring a different method of interpretation. As an introduction to the unit, you will be
required to write a program that can parse a simple text file of the following format:
Where each segment of information is delimited by a single space. The columns represent
the following information:
The city to travel from
The city to travel to
The actual distance between the cities (-1 indicates direct driving between the
cities is not possible)
The straight-line distance to the destination
Information about each pair of cities should be read in and parsed and stored in
appropriate data structures. In particular, a Python dictionary should be created so that the
key is a city name (e.g., 'Melbourne') and the value is a list of cities whose information
can be extracted from the input text file - e.g.,[('Sydney',878,713),('Brisbane',-1,
].
this is the starter code
import sys
print('Number of arguments:', len(sys.argv), 'arguments.')
print('Argument List:', str(sys.argv[1:]))
filename = sys.argv[0]
country_map ={}
with open(filename) as f:
for line in f:
content_list = line.strip().split("")
city1= content_list[0]
city2= content_list[1]
drivingD = content_list[2]
straightD = content_list[3]
if country_map.get(city1):
city1_list = country_map.get(city1)
city1_list.append((city2, int(drivingD), int(straightD)))
country_map[city1]= city1_list
else:
country_map[city1]=[(city2, int(drivingD), int(straightD))]
if country_map.get(city2):
city2_list = country_map.get(city2)
city2_list.append((city1, int(drivingD), int(straightD)))
country_map[city2]= city2_list
else:
country_map[city2]=[(city1, int(drivingD), int(straightD))]
for city, connections in country_map.items():
for connection in connections:
print(city, connection[0], connection[1], connection[2])
need help
 In this programming task, you'll write a simple Python script to

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!