View the step-by-step solution to:


If I have a dictionary d = {'happy': 'going' , 'mad': '**happy***happy', Sad: **mad**mad**mad}

and I need to

replace each occurrence of a key with that keys value how do I get it to loop through the entire dict to update all values to end up with

d = {'happy': 'going' , 'mad': 'going going' ,'Sad': 'going going going going going going'}

I can only get it to update d['mad'] to the correct value. If I am using:

comp = re.compile(('**'key))

And then re.sub(comp,v, str(d))

But evaluating the entire dict at once isn't working but it's the only way I'm able to make a match. Is there a way to use this method but appropriately updating d?

Top Answer

Python code: d = { 'happy' : 'going' , 'mad' : '**happy **happy' , 'Sad' : '**mad **mad **mad' } def resolveStars... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question