成功解决TypeError: unsupported operand type(s) for +: 'dict_items' and 'list'
List 解决 for and 成功 type TypeError unsupported
2023-09-14 09:04:51 时间
成功解决TypeError: unsupported operand type(s) for +: 'dict_items' and 'list'
目录
解决问题
TypeError: unsupported operand type(s) for +: 'dict_items' and 'list'
解决思路
类型错误:+:'dict_items'和'list'不支持的操作数类型
有些人会使用这种方法:z = dict(x.items() + y.items())
这其实就是在内存中创建两个列表,再创建第三个列表,拷贝完成后,创建新的dict,删除掉前三个列表。这个方法耗费性能,而且对于python3,这个无法成功执行,因为items()返回是个对象。
解决方法
将
Z_dict = a.items() + [('b1', 'b2')]
改为
Z_dict = dict( list(a.items()) + [('b1', 'b2')] )
哈哈,大功告成!
相关文章
- diff ->> acl & prefix list
- Unknown column '*' in 'field list' 异常解决
- python中列表(list)函数及使用
- 解决At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JAR
- Coursera Scala 5-5 List:Reduction of Lists
- python 遍历list并删除部分元素
- python list中append()与extend()用法
- 【RF库Collections测试】Get Index From List
- python两个 list 交集,并集,差集的方法+两个tuple比较操作+两个set的交集,并集,差集操作+两个dict的比较操作
- Java中List效率的比较
- mysql问题解决SELECT list is not in GROUP BY clause and contains nonaggregated column
- list容器的大小操作
- SAP Fiori Elements List Report 里的表格类型(tableType)是如何决定出来的
- SAP WebClient UI drop down list(下拉列表)的一个故障和解决方法
- BSP UI Workbench double click component and see view list
- SAP CRM One Order status drop down list generation
- atitit.解决SyntaxError: missing ] after element list"不个object 挡成个str eval ....
- 成功解决极其刁钻bug之TypeError: ‘<=‘ not supported between instances of ‘list‘ and ‘int‘
- 成功解决numpy.ndarray格式类型转数据为list格式数据带有中括号(一行代码搞定!)
- 成功解决AttributeError: 'list' object has no attribute 'ndim'
- 成功解决TypeError: sequence item 0: expected str instance, list found
- 已解决pandas正确创建DataFrame对象的四种方法(通过list列表、dict字典、ndarray、Series对象创建)
- 已解决TypeError:List indices must be integers or slices , not str
- Java中List的contains方法,你用对了吗?
- <LeetCode OJ> 328. Odd Even Linked List
- 解决 java.sql.SQLSyntaxErrorException:Unknown column ‘xxx‘ in ‘field list‘的问题