In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of November 23rd
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #06 exercise sheet]


In this problem you should submit a function as described. Inside the function do not print anything that was not asked!

[IP054] Just an Average Person

Ned Flanders, Springfield's most cheerful and mild-mannered neighbor, has always considered himself an "average" guy, perfectly content to be somewhere right in the middle of things. Whether it’s in a conversation, in the community, or in his personal beliefs, Ned likes to think of himself as a balanced, fair-minded person. One evening, as he organizes a list of Bible study topics for his church group, he finds himself wondering: what would it be like to find the exact middle topic in his list? It's the most "Flanders" place to be, after all!

But there’s a little twist. Sometimes his list has an even number of topics, and sometimes an odd number. In the case of an even list, Ned wants to find the two elements in the middle. For an odd-numbered list, he just needs the single, perfectly central element. This way, he can make sure his "average" choices are as balanced as possible.

The Problem

Write a function middle(lst) that given a list lst of (unique) comparable items returns a list containing the central element, that is, the median, if the list has an odd length; or the two median elements, in increasing order, if the list has an even length.

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

1 ≤ |lst| ≤ 100       Number of elements in list

Example Function Calls Example Output
print(middle(['StAndrew','StJames','StJohn','StPeter','StPhilip']))
print(middle([1,2,3,4,5,6,7,8]))
print(middle([1,9,3,5,7]))
print(middle([8,4,6,2,12,10]))
['StJohn']
[4, 5]
[5]
[6, 8]

Introduction to Programming (CC1024)
DCC/FCUP - University of Porto