基于单独python列表中键的总和值
我有一个名为hits
的字典。
hits = {"The Weeknd": 6, "Maroon 5": 0, "Justin Bieber": 8, "Post Malone": 5}
我还有一个单独的独立列表,标题为Artists
:
artists = ["The Weeknd", "Justin Bieber"]
我想根据Artists中列出的键
hits 字典中的总值总和。 /code>列表(即,答案为6 + 8 = 14)。
I have a dictionary called hits
below.
hits = {"The Weeknd": 6, "Maroon 5": 0, "Justin Bieber": 8, "Post Malone": 5}
I also have a separate, standalone list titled artists
:
artists = ["The Weeknd", "Justin Bieber"]
I'd like to sum the total values in the hits
dictionary based on the keys listed in the artists
list (i.e., answer would be 6 + 8 = 14).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)