예제 #1
0
def get_hubs(city_data, routes):
  """Return a tuple containing a list of hubs and number of connections."""
  connections = {}
  for city in city_data.keys():
  	connections[city] = len(utils.find_adjacent(city, routes))

  maximum = max(connections.values())
  filter_max = lambda (city, connections): connections == maximum
  hub_routes = filter(filter_max, connections.items())

  hubs = []
  for hub in hub_routes:
  	code = hub[0]
  	hubs.append((city_data[code]['name'], code)) # (name, code)
  
  return hubs, maximum
예제 #2
0
def get_cities_by_name(name, city_data, routes):
  """Get detailed information about all airports in a city.
  
  Return the data dictionary for every airport in the city, along with a
  dictionary containing information about adjacent cities.

  Keyword arguments:
  name -- The name of the city.
  """
  cities = utils.cities_named(name, city_data)
  
  adjacent = {}
  for city in cities:
  	ports = utils.find_adjacent(city['code'], routes)
  	adjacent[city['code']] = []

  	for port in ports:
  		adj_name = city_data[port]['name']
  		adj_code = city_data[port]['code']
  		adjacent[city['code']].append((adj_name, adj_code))

  return cities, adjacent