0

I have a nested dictionary that I would like to split based on the value of end qty. I would like to only keep keys in which 'end qty' == 0. I believe it can be done easily with dictionary comprehension, but I can't quite get it right.

import datetime d = { 'ID1' : {'start qty': 13 , 'end qty': 40}, 'ID2' : {'start qty': 10 , 'end qty': 0}, 'UD3' : {'start qty': 30 , 'end qty': 30}, 'ID4' : {'start qty': 20 , 'end qty': 0}, } print { k:v for k, v in d.items() if ['end qty'] == 0 } 
1
  • 4
    if v['end qty'] == 0? Commented Jan 22, 2015 at 21:55

2 Answers 2

1

Just add v in the print statement, in this way

print { k:v for k, v in d.items() if v['end qty'] == 0 } 
Sign up to request clarification or add additional context in comments.

Comments

1

Try this line instead:

print { k:v for k, v in d.items() if v['end qty'] == 0 } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.