Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python dictionaries help WordLength.py Submit Run Grades Reset I # rite a function called word-lengths, which takes in one 2#parameter, a string, and returns a
python dictionaries help
WordLength.py Submit Run Grades Reset I # rite a function called word-lengths, which takes in one 2#parameter, a string, and returns a dictionary where each 3| #nrd. of the string is mapped to an integer representing how punctuation, and 5 #all the lords should be lowercase. You can assume that the 6 #only punctuation marks in the stri ing will be periods mas, question marks, exclamation points, and apostrophes 9 lFor example: word lengths("I ate a bowl of cereal out of a dog bowl today.") 1*:4, today:5,out' :3, "dog':3, "ate':3 121# 13 :1 of2 cereal :6) 14 Hint:Use the split() method to split by spaces and don't 15#forget to remove punctuation marks. Remember also: strings 16 #are immutable, so operations like my-string . lower() don't 17#change the value of my string like list methods: to save 18 #those results, you'd write my-string-my-string. lower() 19,#Your dictionary should not have any duplicate keys (in fact, 26#Python ?0n't allow a dictionary to have duplicate keys) 21 23#Write your function here! 24 Below are sone lines of code that will test your function 26#You can change the value of the variable(s) to test your 27#function with different inputs 28 | # 29#If your function works correctly, this will originally #print : 32 | # 3#The order of the keys may differ, but that's okay! 34 print (word_lengths ("I ate a bowl of cereal out of a dog bowl today.)) Console output will be displayed hereStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started