擅长:python、mysql、java
<p>这是我的例子
索引表示字典键。
在每个循环中,它都会获取密钥,并首先打印值,然后打印密钥</p>
<p>如果您想在不将其放入函数的情况下执行此操作:</p>
<pre><code>dict = {"a": ["1", "2", "3"], "b": ["4", "5"], "c": ["6", "7"]}
for index in dict:
print("Value: " + str(dict[index]), "Key: " + index)
</code></pre>
<p>如果要使用函数执行此操作:</p>
<pre><code>def fuc_dict(dict):
for index in dict:
print("Value: " + str(dict[index]), "Key: " + index)
</code></pre>
<p><strong>输出</strong></p>
<pre><code>Value: ['1', '2', '3'] Key: a
Value: ['4', '5'] Key: b
Value: ['6', '7'] Key: c
</code></pre>