taizilongxu / interview_python

关于Python的面试题
16.63k stars 5.55k forks source link

6.字典推导式中有错误 #93

Open zi-fei-yu-2020 opened 1 year ago

zi-fei-yu-2020 commented 1 year ago

字典这个是一个迭代器对象,参考官方文档找到下列说明,字典只支持Key的遍历,,如果想对key,value,则可以使用items方法,原代码:d = {key: value for (key, value) in iterable}报错,所以正确的代码应该是d = {key: value for (key, value) in iterable.items()}

Qvil85 commented 1 year ago

你的来信我已收到。谢谢。。邱佳涛