python - I created a program, I input keys and values to add to a dictionary but it doesn't work properly
问题描述
liste = []
while True:
key = input("key: ")
val = input("val: ")
words = ('"{}":"{}"'.format(key,val))
liste.append(words)
if len(liste)>=16: #I have 16 words per page
print(liste)
Here is my code. It is working but when I print the list, it is like:
liste = ['"key1","val1"','"key2","val2"','"key3","val3"']
As you can see, there are prime marks (') at the beginning and end of every item. So if I copy and paste those keys and values to my dictionary it won't work. How can I delete these prime marks from my list?
解决方案
To create a dictionary use {key:val}
Ex:
liste = []
while True:
key = input("key: ")
val = input("val: ")
words = {key: val}
liste.append(words)
if len(liste)>=16: #I have 16 words per page
print(liste)
推荐阅读
- animation - 在 React Native Animated 中使用 useNativeDriver 时出错
- php - 坚持在网站上开发一个 cooment 盒子
- angular - 可以在可排序的primeng表中更改列的宽度吗?
- regex - 在正则表达式中使用静态字符串一次,同时使用两种模式 OR
- storage - 如何以 URL 直接访问 Ceph 上的文件
- oracle - Oracle SQL - 使用 if 子句驱动变量
- java - 将特定格式“结构数组结构”的 JSON 文件解析为 spark 数据帧
- c# - 算法优化 - c#
- websphere - 有没有办法在 Websphere Application Server 8.5 中激活较早的 Java 版本?
- sql-server - 使用 SQL Server 身份验证从 WinForms 应用程序连接到 SSRS