I have a question about the accepted answer for this question.
Could you explain why this code:
[{'type':k, 'items':v} for k,v in res.items()]
do the job, i.e. it combines items to list in with same key.
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.
Let’s take it apart:
for k,v in res.items()iterates over the entries ofres, assigning each key and value tokandvrespectively.{'type':k, 'items':v}creates a two-element dictionary. The first element has key'type'and valuek; the second element has key'items'and valuev.[...]is that each entry inresgets converted into a dictionary as explained in step 2, and the resulting dictionaries are stored in a list.