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.

Software ==> Python  (28 exercises)
Version ==> Latest version
Topic ==> Sequences  (7 exercises)
Level ==> Average difficulty
Subject ==> Python training
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

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:

List of words

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:

Problem Hint
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 and close it down.

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post