Reputation:
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
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
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