Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
テキストの本文 (この場合は買い物リスト) から特定のアイテム (「ベイクド ビーンズ」など) の名前を検索するプログラムを作成したいと考えています。次に、リストまたは価格のソースからそれらのアイテムの価格をチェックし、買い物リストの総コストを作成します。これについてどうすればよいですか?
list = '''baked beans spaghetti''' prices = {'baked beans': 1.20, 'spaghetti': 1.30} pricelist = [ ] for line in iter(list.splitlines()): price = prices[line] pricelist.append(price) total = sum(pricelist) print total