我有一个文件,我想从中读取,它是这样的:
Warner, Bros, The Matrix, 5, 2.99
Sony, The Hobbit, 10, 3.99
Warner, Bros, Dark Knight, 4.99
我想从这个文件中创建一个字典,以华纳兄弟为键,其他的都是一个值。我还需要加入所有华纳兄弟在一起,使一个关键和关键的不同值将是电影的名称和数量(矩阵5)和价格。你知道吗
我是这样做的,我读了文件,然后把所有的东西都放到一个列表中,然后用这个列表创建一个字典,但我意识到,我将有多个相同品牌的键;例如华纳兄弟。我如何才能确保我只有一个品牌有多个值?你知道吗
谢谢!你知道吗
请尝试以下操作。。。你知道吗
或者为什么不用两部分的钥匙。。。你知道吗
使用
defaultdict
要打印结果,可以使用这样的方法。我想你把你的资料当作口述,把电影公司的名字当作钥匙
相关问题 更多 >
编程相关推荐