天边一抹灬红 发表于 2020-8-3 10:49:23

python字典

data1 = {}
data1['i'] = '字符串'
data1['from'] = ' AUTO'
data1['to'] = ' AUTO'
data1['smartresult'] = 'dict'
data1['client'] = 'fanyideskweb'
data1['salt'] = '15964214581609'
data1['sign'] = ' 454457e207473b5f63ee6d374d56bd6d'
data1['ts'] = '1596421458160'
data1['bv'] = 'bc250de095a39eeec212da07435b6924'
data1['doctype'] = ' json'
data1['version'] = '2.1'
data1['keyfrom'] = 'fanyi.web'
data1['action'] = 'FY_BY_REALTlME'

data2 = {"i": '字符串', "from": "AUTO", "to": "AUTO", "smartresult": "dict", "client": "fanyideskweb", "salt": "15964214581609", \
      "sign": "454457e207473b5f63ee6d374d56bd6d", "ts": "1596421458160", "bv": "bc250de095a39eeec212da07435b6924", \
      "doctype": "json", "version": "2.1", "keyfrom": "fanyi.web", "action": "FY_BY_REALTlME"}


if data1 == data2:
    print('相同')
else:
    print('不相同')

请问下大佬们为什么输出结果是不一样,这两个字典哪不同了?求解惑

zltzlt 发表于 2020-8-3 10:52:27

data1 的 ' AUTO' 和 data2 的 'AUTO' 不同

Twilight6 发表于 2020-8-3 10:53:53


改成这样即可,你的 data1 里面 data1['from']、data1['to']、data1['sign']、data1['doctype'] 都多了个空格了

data1 = {}
data1['i'] = '字符串'
data1['from'] = 'AUTO'
data1['to'] = 'AUTO'
data1['smartresult'] = 'dict'
data1['client'] = 'fanyideskweb'
data1['salt'] = '15964214581609'
data1['sign'] = '454457e207473b5f63ee6d374d56bd6d'
data1['ts'] = '1596421458160'
data1['bv'] = 'bc250de095a39eeec212da07435b6924'
data1['doctype'] = 'json'
data1['version'] = '2.1'
data1['keyfrom'] = 'fanyi.web'
data1['action'] = 'FY_BY_REALTlME'

data2 = {"i": '字符串', "from": "AUTO", "to": "AUTO", "smartresult": "dict", "client": "fanyideskweb", "salt": "15964214581609", \
      "sign": "454457e207473b5f63ee6d374d56bd6d", "ts": "1596421458160", "bv": "bc250de095a39eeec212da07435b6924", \
      "doctype": "json", "version": "2.1", "keyfrom": "fanyi.web", "action": "FY_BY_REALTlME"}


if data1 == data2:
    print('相同')
else:
    print('不相同')

永恒的蓝色梦想 发表于 2020-8-3 10:55:05

data1 中的 AUTO 前面多一个空格。

天边一抹灬红 发表于 2020-8-3 10:57:08

粗心了,谢谢大佬们

有爱的咖啡 发表于 2020-8-3 11:47:05

{:10_277:}这么一大串 正常
页: [1]
查看完整版本: python字典