在python中压缩键值对

Tes*_*ida 5 python

我需要将输出从数字 1 = 0 更改为 (1:0) 或 ('1':0)。我想更改为键值对。下面是我正在使用的代码。

numberlist = [1]
val_list = [0]
for (number, val) in zip(numberlist, val_list):
    print 'number ', number, ' = ', val
Run Code Online (Sandbox Code Playgroud)

输出:number 1 = 0 所需的输出是:('1':0) or (1:0)

Far*_*n.K 6

numberlist = [1, 2, 3]
val_list = [4, 5, 6]

mydictionary = dict(zip(numberlist,val_list))
Run Code Online (Sandbox Code Playgroud)

这将创建一个以numberlist作为键和val_list作为值的字典。

>>> mydictionary
{1: 4, 2: 5, 3: 6}
>>> mydictionary[1]
4
Run Code Online (Sandbox Code Playgroud)