The CTP Book

A book for teaching Computational Thinking and Programming skills to people with a background in the Humanities

View on GitHub

Chapter “Organising information: ordered structures”, exercise 1

Text

Write a sequence of instructions in Python to create a list with the following elements ordered alphabetically: "​Harry"​, "​Draco"​, "​Hermione"​, ​"​Ron"​, "​Severus"​.

Answer

my_list = list()
my_list.append("Draco")
my_list.append("Harry")
my_list.append("Hermione")
my_list.append("Ron")
my_list.append("Severus")

Additional material

The runnable Python file is available online.