小编Jet*_*ett的帖子

如何在Python中逐行打印字典?

这是字典

cars = {'A':{'speed':70,
        'color':2},
        'B':{'speed':60,
        'color':3}}
Run Code Online (Sandbox Code Playgroud)

用这个 for loop

for keys,values in cars.items():
    print(keys)
    print(values)
Run Code Online (Sandbox Code Playgroud)

它打印以下内容:

B
{'color': 3, 'speed': 60}
A
{'color': 2, 'speed': 70}
Run Code Online (Sandbox Code Playgroud)

但我希望程序打印出来像这样:

B
color : 3
speed : 60
A
color : 2
speed : 70
Run Code Online (Sandbox Code Playgroud)

我刚开始学习字典,所以我不知道该怎么做.

python printing dictionary

146
推荐指数
8
解决办法
57万
查看次数

如何在Python的字典中打印给定值的键?

例如,假设我们有以下字典:

dictionary = {'A':4,
              'B':6,
              'C':-2,
              'D':-8}
Run Code Online (Sandbox Code Playgroud)

如果给出它的价值,你如何打印某个键?

print(dictionary.get('A')) #This will print 4
Run Code Online (Sandbox Code Playgroud)

你怎么能倒退呢?即,不是通过引用键获取值,而是通过引用该值来获取键.

python dictionary key

5
推荐指数
1
解决办法
2万
查看次数

如何从python中的字典中删除所有0?

可以说我有一个这样的字典:

{'1': 2, '0': 0, '3': 4, '2': 4, '5': 1, '4': 1, '7': 0, '6': 0, '9': 0, '8': 0}
Run Code Online (Sandbox Code Playgroud)

我想删除值为零的所有项目

所以它就像这样

{'1': 2, '3': 4, '2': 4, '5': 1, '4': 1}
Run Code Online (Sandbox Code Playgroud)

python dictionary

1
推荐指数
2
解决办法
4171
查看次数

在Python中,如何检查数字在输入中出现的次数?

比如说

numbers=input("Enter numbers: ")
Run Code Online (Sandbox Code Playgroud)

如果有人输入11234458881

我怎样才能输出

1发生3次

2发生1次

3发生1次

4次发生2次

等等

python count digits

0
推荐指数
1
解决办法
874
查看次数

标签 统计

python ×4

dictionary ×3

count ×1

digits ×1

key ×1

printing ×1