我有一个城市列表,每个城市都有一个名称、一个真值或假值,然后是另一个与其相连的城市的列表。如果所有城市都是 True 并且 False 不是所有城市都是 True,我如何在 Python 中编写一个函数来表示 True?
以下是我的城市是如何建造的:
def set_up_cities(names=['City 0', 'City 1', 'City 2', 'City 3', 'City 4', 'City 5', 'City 6', 'City 7', 'City 8', 'City 9', 'City 10', 'City 11', 'City 12', 'City 13', 'City 14', 'City 15']):
"""
Set up a collection of cities (world) for our simulator.
Each city is a 3 element list, and our world will be a list of cities.
:param names: A list with the names of the cities in the world.
:return: a list of cities
"""
# Make an adjacency matrix describing how all the cities are connected.
con = make_connections(len(names))
# Add each city to the list
city_list = []
for n in enumerate(names):
city_list += [ make_city(n[1],con[n[0]]) ]
return city_list