Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace keys in a dictionary

I have a dictionary

event_types={"as":0,"ah":0,"es":0,"eh":0,"os":0,"oh":0,"cs":0,"ch":0}

How can I replace a by append, s by see, h by horse, e by exp with a space in between.

Output something like:

{"append see":0,"append horse":0,"exp horse":0....}
like image 386
Abhishek Bhatia Avatar asked Sep 17 '15 05:09

Abhishek Bhatia


1 Answers

Not sure if you can append or not, but you can do the following one liner:

>>> dict={}
>>> dict={"a":"b"}
>>> dict["aha"]=dict.pop("a")
>>> dict
{'aha': 'b'}

You can traverse the keys and change them according to your need.

like image 77
Ahsanul Haque Avatar answered Oct 14 '22 17:10

Ahsanul Haque