My Code :
dict( (k,v) if k in ['1','2','3','4'] else (k,None) for k,v in {'1':'one','2':'two'}.items() )
Expected Output :
{'1': 'one', '2': 'two', '3':None, '4':None}
Actual Output :
{'1': 'one', '2': 'two'}
Please help !
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
forclause only contains 2 items, so your final dict is only going to have 2 items. The 4-item list is only used as a comparison, not as a source of values to use.