1 year ago

#126435

test-img

vimedit

how to replace word in dict without overwriting the original dict type

    Envs = ["re","pr","qa"]
    k = {'ro.env.create': 'boolean, loop', 'ticket.instructions': 'text', 'Group.env': 'text, loop'}
    for env in Envs:
        j = str(k).replace("env", env.lower())
        for i in j:
            if "boolean" in j[i]:
                print "boolean"
                print(k)
            else
                print "not boolean"

Expected Output: I should be able to replace env and iterate through keys and values in the dict

I have above dict which has env as string in some keys, so i want to replace the env string with the above Envs list and run in a loop for further processing.

I tried replacing it using replace module, but it is replacing the dict type, and when i am looping for each element in Envs list, it is not working.

python

python-2.7

jython

jython-2.7

0 Answers

Your Answer

Accepted video resources