Question: Question 4: Create a dictionary from a given list rite a function that takes a list of strings as an input and returns a dictionary:
Question 4: Create a dictionary from a given list rite a function that takes a list of strings as an input and returns a dictionary: each key in the dictionary represents the length of the word and the corresponding value is the list of the strings of this length. Hint 1: Use method append that appends values to a given key: dict (key].append (value Hint 2: The very first value that you add to you dictionary must be a list (of strings). Then appending another string is fine, since you add to the list, and lists are mutable. def new _dict (data): "w "Returns a dictionary, where each key corresponds to the length of a word, values are the lists of words of the same length: >>> d-["Once " , "upon", "a", "tine", "in", "America" ] output new dict (d) s>> print (output) (4: ['Once, 'upon',time', 1: Ma 2 in', 7: 'America'1 s>d["Never""ay,"Never" >>output- new dict (d) >>> print (output) (5: ['Never','Never'), 3: ('aay'1, >>dSo",say", "we", "al1, s>> output-new dict (d) >>print (output) SThe"needs" , "the", "many", "outweigh" "the", needs"WOEthe"."Eew"" >>s output new dict (d) >print (output) 3: The.the,thethe', few'), 5: 'needs,'needs'1 2: of.of'. : many'.8:'outweigh, **YOUR CODE GOES HERE
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
