Skip to content

Instantly share code, notes, and snippets.

@johnmcc
Created April 20, 2018 12:40
Show Gist options
  • Save johnmcc/dc3511ee61de1654931d30c6566578d2 to your computer and use it in GitHub Desktop.
Save johnmcc/dc3511ee61de1654931d30c6566578d2 to your computer and use it in GitHub Desktop.

Part 1

Using a loop, and the following list:

ages = [5, 15, 64, 27, 84, 26]
  • Find the sum total of the values in this list
  • Find the average (mean) value of the items in the list

Part 2

Using a single list comprehension, and the following list:

words = ["The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog"]
  • Build a new list, with the first letter from each word
  • Convert each letter to lower case

Expected output: ["t", "q", "b", "f", "j", "o", "t", "l", "d"]

Hint: Strings in Python work as if they were a tuple full of characters. How would you get the first element from a tuple or list?

Part 3

Implement a basic linear search algorithm using Python's for and if keywords.

Given the following data structure:

pupils = ["Alison", "James", "Stephen", "Mandy", "Henry"]

Search through the list and check if the name "Jack" is included. Print out an appropriate message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment