Suppose I have a dictionary, and it’s nested with dictionaries inside.
I want to join all the values of that dictionary, recursively?
' '.join(d.values())
That works if there are no nests.
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 following works for any non-recursive nested dicts:
Edit: Support for recursive dicts
If you need to support self-referencing dicts, you need to extend the above code to keep track of all processed dicts and make sure you never attempt to process a dictionary that you’ve already seen. The following is a reasonably cheap, yet readable way to do it: