python - 如何在没有方括号和撇号的新行中打印出python中的字典列表
问题描述
如何打印出这样的字典列表?:
Tino Black
Alex Blue
Meow Red
Woof White
我希望左列是名称,右列是每个名称的颜色。
这是我的代码:
ask = input("Name and colour: ")
colourList = {}
while ask:
name, colour = ask.split()
colourList[name] = colour
ask = input("Name and colour: ")
print(colourList)
解决方案
您可以这样做,例如:
for name, color in colourList.items(): # this is actually a colourDictionary
print(name, color)
推荐阅读
- python - 如何在ortools python中设置约束
- pvlib - 太阳能光伏 - 如何将每日 GHI 转移到倾斜的表面?
- mysql - macOS Catalina 必须执行 source ~/.bashrc 才能使用 mysql 命令
- arrays - 如何显示来自谷歌表的最新 3 个数据
- c# - 使用 async-await 进行数据库查询
- vue.js - Vue:在 v-if/else 中使用 Vue 转换?
- jquery - 如何仅在图标单击时显示日历?
- java - 微服务 - 启动配置服务器 org.springframework.boot.context.properties.bind.BindResult 时出错
- javascript - 在 Reactjs 中将组件作为道具传递
- javascript - 有没有更好的方法将数组值动态插入到 Excel 工作表中?