python - 使用 for 循环对每个键取多个值
问题描述
student_marks = {'Raj':[20,30,40,48], 'Raja':[25,35,46,22]}
我想编写一个代码,使用户能够以上述形式输入。我已经看到了针对每个键获取一个值的代码片段,但找不到将列表作为值获取的代码片段。
解决方案
我猜你想要这样的东西
dic = {}
while True:
student = input("enter student name : ")
if student:
mark = input("enter student mark split by ',' : ").split(",")
dic.update({str(student): mark})
else:
break
print(dic)
推荐阅读
- sql - 如何减去两个特定行并创建带有答案的自定义列
- python - 我在 python 中使用 postgresql 进行注册编码时遇到了重大问题
- javascript - 我想使用 jsdoc 在我的代码中添加解释
- javascript - 如何在 5 秒后禁用按钮(discord.js)
- javascript - 如何根据日期自动在猫鼬中添加文档
- azure - Azure AD b2c 自定义策略签名/注册错误:-AADB2C:加密密钥必须是 256 位密钥错误
- javascript - 在 JavaScript 中解析和修改一个 html 字符串
- java - ActiveMQ 连接 URL 中的掩码密码
- r - 如何使用 R 中的 phyloseq 对象从 ANCOM 获得有意义的结果?
- python - 从 RGB 值在 Google Collab 中打印图像