同我有城市的列表,每个城市都有一个名字,一个真或假的值,然后用它连接到其他城市的名单。我如何在Python中编写函数来表示True,如果所有的城市都是True且False不是全部都是True?确定是否所有项目都在Python
下面是我的城市作了:
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
尝试[了'所有()'函数(http://docs.python.org/3/library/functions.html#all)。 – Ryan
我不会用一个列表作为默认参数,肯定不会这么长的一个。 –