Jun-09-2018, 09:51 PM
(Jun-09-2018, 08:56 PM)ljmetzger Wrote:for key in dic.keys(): for key2 in dic[key]: dic2[key + ' ' + str(key2)] = dic[key][key2]
I gave the code a cursory look, and this part has drawn my attention. Iterating over
dict.keys()
maybe was acceptable in 2.2 or 2.3 - but for years it has been considered un-Pythonic, since iteration over dictionary already yields keysMoreover, you can iterate over
items
for key, dic2 in dic.items: for key2, value2 in dic2.items() dic2[key + ' ' + str(key2)] = valueActually, a lot of things in your code look off - converting to
dict
, and then working hard to rearrange - but I am not up to the task now
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.