Python | Sequences exercise | Performing various operations on a tuple of common words
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.
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Open and run the file shown in the folder above. It should give you a list of the 25 most common words in written English, and various ways of analysing them:
If you run this program, you should see 7 headings just waiting to be filled in!
See how many of the bits of information from A to G you can show, using these hints:
|A - number of words||The len function gives the number of items in any sequence.|
|B - first 5 words||Use the syntax sequence[start:stop] .|
|C - last 3 words||You can use negative numbers to say how many items before the end of the sequence you want to stop.|
|D - every 5th word||Use the syntax sequence[start:stop:step value] .|
|E - four-letter words||Use the iterator for X in Y:, and within this loop test whether the len of each item equals 4.|
|F - Words starting with w||Use the same iterator syntax, but this time apply the startswith method to each item to see if it begins with a w.|
|G - words in order||Tuples are immutable, so use the list function to convert your tuple to a list then apply the sort method.|
You can see what answers you should get below.
Here are the answers you should get to the various parts of this exercise:
These are the answers you should get.
Save this program as Analysing common words.py and close it down.