私はこのデータを持っています:
inventory = { HAMMER: (10,100),
SCREW: (1, 1000),
NAIL: (1, 1000),
SCREWDRIVER: (8, 100),
DRILL: (50, 20),
WORKBENCH: (150, 5),
HANDSAW: (15, 50),
CHAINSAW: (80, 30)
}
私は次の関数を書きました:
def get_items(cheapness):
""" Return a list of (item, (price, count)) tuples that are the given
cheapness. Note that the second element of the tuple is another tuple. """
if cheapness == 'CHEAP':
return [(key, value) for (key,value) in inventory.items() if value in ((cost,quantity) for (cost, quantity) in inventory.values() if cost < 20)]
elif cheapness == 'MODERATE':
return [(key, value) for (key,value) in inventory.items() if value in ((cost,quantity) for (cost, quantity) in inventory.values() if 20 < cost < 100)]
elif cheapness == 'EXPENSIVE':
return [(key, value) for (key,value) in inventory.items() if value in ((cost,quantity) for (cost, quantity) in inventory.values() if cost > 100)]
私の問題は、 を実行するprint type(get_items(CHEAP))
と、 が得られること<type 'NoneType'>
です。結果をリストとして返すにはどうすればよいですか?