Python2.7中dict.values()+dict.values(),在Python3.5中解决办法
2017-12-13 10:48
309 查看
首先来看下在Python2.7中代码:
输出结果为是一个list:
/usr/bin/python3.5 /home/tream/C3D/C3D-tensorflow/test.py
Traceback (most recent call last):
File “/home/tream/C3D/C3D-tensorflow/test.py”, line 16, in
r=w.values()+b.values()
TypeError: unsupported operand type(s) for +: ‘dict_values’ and ‘dict_values’
w={
‘a’:1,
‘b’:2,
‘c’:3
}
b={
‘aa’:4,
‘bb’:5,
‘cc’:6
}
c=list(w.values())
x=list(b.values())
q=c+x
print(q)
/usr/bin/python2.7 /home/tream/Desktop/2/tt/test.py
[1, 3, 2, 4, 6, 5]
Process finished with exit code 0
w={ 'a':1, 'b':2, 'c':3 } b={ 'aa':4, 'bb':5, 'cc':6 } r=w.values()+b.values() print(r)
输出结果为是一个list:
/usr/bin/python2.7 /home/tream/Desktop/2/tt/test.py
[1, 3, 2, 4, 6, 5]
Process finished with exit code 0
下面是在Python3.5中:
w={ 'a':1, 'b':2, 'c':3 } b={ 'aa':4, 'bb':5, 'cc':6 } r=w.values()+b.values() print(r)
结果:
/usr/bin/python3.5 /home/tream/C3D/C3D-tensorflow/test.py
Traceback (most recent call last):
File “/home/tream/C3D/C3D-tensorflow/test.py”, line 16, in
r=w.values()+b.values()
TypeError: unsupported operand type(s) for +: ‘dict_values’ and ‘dict_values’
解决办法就是先强制转换到解决办法就是转换成list再加,Kidding me?确实是这样的。再见!
w={
‘a’:1,
‘b’:2,
‘c’:3
}
b={
‘aa’:4,
‘bb’:5,
‘cc’:6
}
c=list(w.values())
x=list(b.values())
q=c+x
print(q)
输出结果:
/usr/bin/python2.7 /home/tream/Desktop/2/tt/test.py
[1, 3, 2, 4, 6, 5]
Process finished with exit code 0
相关文章推荐
- Ubuntu16.04下在Python2.7安装OpenCV3.2.0出现的问题与解决办法
- Python2.7编码问题解决办法
- 安装scipy或者numpy时弹出python2.7 was not found in the registry 的解决办法: python的注册与注销方法
- 使用Gevent程序正常运行出现这个异常KeyError(155880780,) in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored解决办法
- python 报 python 2.7 is required ,which is not found in registry 的错误的解决办法
- python2.7在使用reload(sys)后,再使用print语句无输出,有解决办法吗?
- python2.7使用logging模块记日志,中文记入后乱码解决办法
- python2.7与python3.5共存问题解决
- python3.5在windows 2008安装报错解决办法
- python2.7,Ubuntu14.04环境下pip安装插件,cffi插件出现一下错误解决办法。
- Python 2.7安装setuptools时的UnicodeDecodeError解决办法
- python2.7 使用super关键词 报错 TypeError: must be type, not classobj 解决办法
- python 2.7 升级安装python 3.5 安装pip的办法
- anaconda2下安装psycopg2出现python 2.7 required not found in registry解决办法
- centos下装完python2.7无法使用yum的解决办法
- python2.7 使用super关键词 报错 TypeError: must be type, not classobj 解决办法
- python2.7在使用reload(sys)后,再使用print语句无输出的解决办法
- 关于Python2.7得到结果乱码的问题解决办法
- python里面的字典dict类型键名为中文的解决办法
- command not found: django-admin.py的解决办法(python2.7)