Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
497 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | Python (34 exercises) |
Topic ==> | Comprehensions (1 exercise) |
Level ==> | Average difficulty |
Subject ==> | Python training |
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
Open the Python program in the above folder and run it - you should see a speech from Julius Caesar:
Will Shakespeare - master of the metaphor.
Analyse this speech to see the word count as follows:
Surprisingly, there are more two-letter words than any other.
Here are some ideas for how to proceed:
Task | Hint |
---|---|
Getting a list of words | Use the split function to split your text, using a space character as a delimiter. |
Removing punctuation | Some words contain , and . characters, and some contain \n line breaks. Loop over the list of words, applying the replace function to each to remove these extra characters. You should also use the lower function to convert each word to lower case, to make sure that And is counted with and, for example. |
Producing the output | Loop over all the numbers in a range from 1 to (say) 20. For each number, use a list comprehension to find how many words there are with this many letters in (see below), and apply an if statement to print out a message if the number of words is more than zero. |
Here is some suggested text for your list comprehension, to give you the idea of the syntax:
# show number of words with this many letters
# (this uses a list comprehension)
number_words = len([x for x in words if len(x) == num])
There are probably better and definitely other ways to solve this; feel free to do your own thing (the result is what counts ...).
When you've got this working, save your program as Speech impediment.py and close it down.
You can find other training resources for the subject of this exercise here:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2025. All Rights Reserved.