AlessandroZ / LaZagne

Credentials recovery project
GNU Lesser General Public License v3.0
9.52k stars 2.04k forks source link

Mac LaZagne: Adding two dicts together in Python 3 #532

Closed cclauss closed 4 years ago

cclauss commented 4 years ago

This solution to https://github.com/AlessandroZ/LaZagne/issues/431#issuecomment-552210931 should work in both Python 2 and Python 3.

% python3

>>> dic = {"A": 0}
>>> dic_tmp = {"B": 1}

>>> dict(dic.items() + dic_tmp.items())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'dict_items' and 'dict_items'

>>> dict(list(dic.items()) + list(dic_tmp.items()))
{'A': 0, 'B': 1}

% python2

>>> dic = {"A": 0}
>>> dic_tmp = {"B": 1}

>>> dict(dic.items() + dic_tmp.items())
{'A': 0, 'B': 1}

>>> dict(list(dic.items()) + list(dic_tmp.items()))
{'A': 0, 'B': 1}
AlessandroZ commented 4 years ago

Cool, thanks a lot :+1: