Home:ALL Converter>TypeError: unsupported operand type(s) for &: 'list' and 'list' python

TypeError: unsupported operand type(s) for &: 'list' and 'list' python

Ask Time:2018-12-17T18:40:31         Author:spark dev

Json Formatter

I get this really weird error when I am writing my Python code. It is a TypeError that I get to do with unsupported operand types. The error I get is below :

names_in_both = jsonDataprevFile.keys() & jsonDatacurrFile.keys()
TypeError: unsupported operand type(s) for &: 'list' and 'list'

Author:spark dev,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53813465/typeerror-unsupported-operand-types-for-list-and-list-python
Cavaz :

I'm guessing you are trying to find common keys in the dicts. Unfortunately, dict.keys returns a list, not a set, which does not support the intersection operator. Just cast the output as set.\nnames_in_both = set(jsonDataprevFile.keys()) & set(jsonDatacurrFile.keys())\n\nUpdate: as per python 3, dict.keys() returns a dict_keys object, which does allow performing d1.keys() & d2.keys()",
2018-12-17T10:45:07
nishant :

I guess you want this\n\nnames_in_both = jsonDataprevFile.keys() + jsonDatacurrFile.keys()\n",
2018-12-17T10:43:49
yy