Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedpython 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 here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions

Question

6. Explain the power of labels.

Answered: 1 week ago

Question

10. Discuss the complexities of language policies.

Answered: 1 week ago