python报错 ValueError: dictionary update sequence element #0 has length 1; 2 is require
字符串转字典要用eval(),这个方法很多书上都没有介绍, 有关eval()的用法,传送门: ss = ['a','bc','def']>>> dict(ss)Traceback (most recent call last): File "", line 1, in ValueError: dictionary update sequence element #0 has length 1; 2 is required>>> eval(ss)Traceback (most recent call last): File "", line 1, in TypeError: eval() arg 1 must be a string, bytes or code object>>>>>> ss = ['aa','bc','def']>>> dict(ss)Traceback (most recent call last): File "", line 1, in ValueError: dictionary update sequence element #2 has length 3; 2 is required>>> ss = ['a','bc','de']>>> dict(ss)Traceback (most recent call last): File "", line 1, in ValueError: dictionary update sequence element #0 has length 1; 2 is required>>> ss = ['aa','bc','de']#改为2个字符就好啦!>>> dict(ss){'a': 'a', 'b': 'c', 'd': 'e'}>>> ss = ['awed','webc','wede']>>> dict(ss)Traceback (most recent call last): File "", line 1, in ValueError: dictionary update sequence element #0 has length 4; 2 is required>>>
这个仅仅是因为,需要转换的字符串不是2位!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~