Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (anonymous):

In the given dictionary, each key is a single lowercase letter and each value is a list of lowercase words that start with that letter. Based on the given dictionary, return a new dictionary in which each key is a single lowercase letter and each value is the number of lowercase words that start with that letter.''' is this right if i am writing like this ? def get_letter_counts(old_dict): new_dict = {} for letters in old_dict: for words in letters: word_num = len(words)+1 new_dict[letters] = word_num return new_dict

OpenStudy (anonymous):

Close. But you didn't need any sort of inner loop. "for letters in old_dict" should actually be "for letter(singular) in old_dict" because during each iteration you are only dealing with a single letter. Once you have this single letter all you need to do is take the length of old_dict[letter] and store it to new_dict[letter]. Try this: def get_letter_counts(old_dict): new_dict = {} for letter in old_dict: new_dict[letter] = len(old_dict[letter]) return new_dict

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!