Python2.7中dict.values()+dict.values(),在Python3.5中解决办法
来源:互联网 发布:mac邮箱无法验证账户 编辑:程序博客网 时间:2024/06/06 08:49
首先来看下在Python2.7中代码:
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
阅读全文
1 0
- Python2.7中dict.values()+dict.values(),在Python3.5中解决办法
- python2.7错误for k,v in dict: ValueError: too many values to unpack
- 在python2.x中使用dict类型解决没有python3.x中的nonlcoal的问题
- 在Python2.x和Python3.x中dict.keys()的差异
- dict里面的itervalues() 方法比 values()
- super(Dict) / zip(names, values) python
- Python3中dict按value排序
- Python中 dict.items() dict.iteritems()区别
- Python中 dict.items() dict.iteritems()区别
- Python中 dict.items() dict.iteritems()区别
- Python3中dict.keys()转换成list类型
- Python中dict详解
- Python中dict详解
- Python中dict 字典
- Python中dict详解
- Python中dict详解
- Python中dict使用
- Python中dict详解
- 设计模式(二十三)------23种设计模式(15):备忘录模式
- 教你如何用显卡挖比特黄金BTG(BitcoinGold)BTG挖矿教程
- 快速幂(Fast Power)
- 分布式配置管理平台的设计与实现
- 原型图设计大全
- Python2.7中dict.values()+dict.values(),在Python3.5中解决办法
- Nginx-防止图片盗链
- PAT 1013. 数素数
- js页面格式化时间戳
- 正则表达式面试题
- 绝对路径和相对路径
- 大数据相关之flume
- colorAccent,colorPrimary,colorPrimaryDark……来这里你就明白了
- Spring Boot配置文件application properties配置详解