我正在Python2.6中编写一些脚本。我总是在python2.7中写,所以我不知道为什么这句话错了:
<?php
$json = '{
"https://example.com/images/I/4162nAIaRCL._SX425_.jpg": [425, 425],
"https://example.com/images/I/4162nAIaRCL._SY355_.jpg": [355, 355],
"https://example.com/images/I/4162nAIaRCL._SX466_.jpg": [466, 466],
"https://example.com/images/I/4162nAIaRCL._SY450_.jpg": [450, 450],
"https://lastexample.com/images/I/4162nAIaRCL.jpg": [500, 500]
}';
$array = json_decode($json, true);
$keys = array_keys($array);
echo end($keys); // https://lastexample.com/images/I/4162nAIaRCL.jpg
错误:
print(sys.version)
2.6.6(r266:84292,2018年3月15日,13:11:05)[GCC 5.4.0 20160609]
keys = ['b','h']
d = {k:0代表k中的k,如果没有k代表['time_us','status']}
档案“”,第1行
keys = ['h','b'] d = {k:0 for k in keys if not k in ['time_us', 'status']}
答案 0 :(得分:3)
字典理解在Python 2.7中出现。
对于Python 2.6,您可以传递dict
一系列键值对。
d = dict((k,0) for k in keys if k not in ('time_us', 'status'))