Last active
January 4, 2017 08:53
-
-
Save davehewy/eca47bac023be0cd7c66d79d5dfae236 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hello Candidate! | |
# Welcome to the EE Python Test. | |
# As I will have mentioned in the interview we are not overly interested | |
# in the absolute quality of your code, just your ability to approach problems. | |
# All code solutions should be tar/zip'd up and sent to the recruiter to pass | |
# back to us. Thanks. | |
# Task 1 | |
# | |
# You must create a command line script that is able to retrieve data from a web server, process that data and | |
# output the correct results to the console. The code should be written in such a way that all of the required test | |
# results can be obtained by passing in command line options to the script. | |
# | |
# The script will need to be able to handle errors gracefully and will need to implement some kind of | |
# caching/storage so that once executed successfully it could still be used should an Internet connection become | |
# unavailable. | |
# | |
# The script should be structured in such a way as to allow for future extension or maintenance to be as easy as | |
# possible. | |
# The following website contains a list of all towns & cities in the UK, and the population as per the 2011 census data. | |
# http://www.lovemytown.co.uk/Populations/TownsTable3.asp | |
# Your task will be to construct a command line script thats capable of returning the following: | |
# - The top 20 cities by population | |
# - The top 10 towns by population | |
# - The smallest 10 cities by population | |
# - The smallest 10 towns by population | |
# - The total number of towns and cities with a population of X (X should be a configurable cmd line parameter) | |
# The script should accept a name and a start and end year as input parameters, e.g. | |
# ./scriptName [towns|cities|population] [top|bottom|over] [limit] | |
# So expected behaviour might be: | |
# ./scriptName town top 20 | |
# ./scriptName cities bottom 20 | |
# ./scriptName population over 10000 | |
# Note the script to execute the first coding task must be SEPERATE from this file. | |
# Task 2. | |
# Printing directory contents | |
def print_directory_contents(sPath): | |
""" | |
This function takes the name of a directory | |
and prints out the paths of files within that | |
directory as well as any files contained in | |
contained directories. | |
This function is similar to os.walk. Please don't | |
use os.walk in your answer. We are interested in your | |
ability to work with nested structures. | |
""" | |
fill_this_in | |
# Task 3. | |
# Place the following functions below in order of their efficiency. | |
# They all take in a list of numbers between 0 and 1. The list can be quite long. | |
# An example input list would be [random.random() for i in range(100000)]. | |
# How would you prove that your answer is correct? | |
def f1(lIn): | |
l1 = sorted(lIn) | |
l2 = [i for i in l1 if i<0.5] | |
return [i*i for i in l2] | |
def f2(lIn): | |
l1 = [i for i in lIn if i<0.5] | |
l2 = sorted(l1) | |
return [i*i for i in l2] | |
def f3(lIn): | |
l1 = [i*i for i in lIn] | |
l2 = sorted(l1) | |
return [i for i in l1 if i<(0.5*0.5)] | |
# Task 4 | |
# What does this stuff mean *args and **kwargs. Why would we use it? | |
# Answer below using a python comment. | |
def f(*args,**kwargs): print(args, kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment