user11124889
user11124889

Reputation:

how to use values in dictionary in sub process

my_dict is dictionary have values

sample value :

{0: {'Id': 'd1', 'name': 'elpato', 'email': '[email protected]'}, 1: {'Id': 'd2', 'name': 'petoka', 'email': '[email protected]'}}

how to use name key in loop of subprocess so that it runs till count of name ends in a loop one by one.

example :

 subprocess.call(["...",name])

here name should be in loop using values of dict name, so here it should loop and call the subprocess two times i.e,. elpato and petoka. in case of dict having 1000 values it should loop 1000 times

Upvotes: 0

Views: 258

Answers (2)

balderman
balderman

Reputation: 23815

myDict = {0: {'Id': 'd1', 'name': 'elpato', 'email': '[email protected]'}, 1: {'Id': 'd2', 'name': 'petoka', 'email': '[email protected]'}}
for name in [v['name'] for v in myDict.values()]:
    #subprocess.call(["...", name])
    print(name)

output

elpato
petoka

Upvotes: 1

DanStu
DanStu

Reputation: 174

As Green Cloak Guy suggested, we can use a for loop

myDict = {0: {'Id': 'd1', 'name': 'elpato', 'email': '[email protected]'}, 1: {'Id': 'd2', 'name': 'petoka', 'email': '[email protected]'}}
for key in myDict:
    print(myDict[key]['name'])

Upvotes: 1

Related Questions