Question: Write a function create _ spatial _ network ( itineraries ) that takes itineraries ( a list of tuples ) and returns for each location
Write a function createspatialnetwork itineraries that takes itineraries a list of tuples and returns for each location its neighbors and distances to them. A location is considered to be a neighbour of another location if it can be reached by a single road one edge
Input:
itineraries: a list of tuples, where each tuple is of the form location location distance location and location are the string labels for these locations and distance is an integer.
Your function should return a list of tuples, where each tuple is of the form location neighbours neighbours should be of the form neighbour distanceneighbour distance and be sorted by their distances in the increasing order If two or more neighbors have the same distance to the location, tiebreak by alphanumeric order on their labels.
Note that in addition to the neighbors, the overall list has to be sorted.
You may assume:
Distances are nonnegative integer values
Inputs are correctly formatted data structures and types
There are no duplicate entries itineraries, and in each neighbor pair only appear once ie no LLLL
Here is a diagram of an example network:
For the network above, this would be a possible itineraries and the function should return the following:
createspatialnetworkitineraries
A different example not pictured:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
