FAQ: Code Challenge: Dictionaries - Word Length Dict

This community-built FAQ covers the “Word Length Dict” exercise from the lesson “Code Challenge: Dictionaries”.

Paths and Courses
This exercise can be found in the following Codecademy content:

FAQs on the exercise Word Length Dict

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

3 posts were split to a new topic: Could this be solved with list comprehension?

3 posts were split to a new topic: Why is .append() working with my code?

2 posts were split to a new topic: How does the provided solution create new keys?

A post was merged into an existing topic: Why isn’t .append() working with my code?

I can’t wrap my head around the code below. Can someone please enlighten me?

How is it possible that when the code newdict[word] = len(word) runs, it knows that it’s the VALUE and not the KEY that it needs to update?

    newdict[word] = word
    newdict[word] = len(word)
def word_length_dictionary(words): 
  newdict = {}
  for word in words: 
    newdict[word] = word
    newdict[word] = len(word)
  return newdict

Also, I’m still trying to get a good grip on Dictionaries and although I might be able to finish this topic, I may not be confident enough to move forward. Do you suggest I re-take the whole practice? Should I read up/watch from other resources online to solidify my knowledge? I welcome any suggestions. Thank you for your help.

“updating” a key would mean removing one key and inserting another
changing it in-place does not make sense. the key is the place.

(also that would be a useless dict, if you have a word then you have the length as well, there’s no reason to create a lookup table for that)