Python | Dictionaries exercise | Create a dictionary to hold tall buildings

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 ==> Dictionaries  (1 exercise)
Level ==> Average difficulty
Subject ==> Python training

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.

The 6 tallest buildings in the world (as of September 2021, anyway) are:

Tallest buildings

The Shard in London (the tallest building in Europe) comes in at 96th in the list (in case you were wondering).

Create a program which stores this information in a dictionary using:

  • The building name as the key; and
  • A tuple or list containing the building's rank, city, country and height in metres as the value.

Loop over the items in this dictionary to print out the contents, to get:

List of buildings

A list of the tallest buildings extracted from the dictionary's keys and values. Each dictionary item's value will contain a list or tuple, so you'll need to extract the building information from this each time round the loop.

As a reminder of the syntax for working with dictionaries, this code would list out the names and colours of the Wise Owls' cats:

# create a dictionary of Wise Owl cats

cats = {

"Agatha": "Black and white",

"Annie": "Tortoiseshell",

"Marv": "Not sure",

"Neo": "Black and white",

"Sabrina": "Black",

"Salem": "Black"


# loop over dictionary's records

for cat_name, colour in cats.items():

print(cat_name + " is " + colour)

Finally, something to ponder: was a dictionary the most suitable way to store this data or not? 

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