Kodewick
Start learning →
Starter←→0 / 100

Front and back

#043StarterLists2 min

In PE class the teacher wants to know who stands at the front and the back. Write ends_of_line(line) to return [first, last]. If only one person is in line, they are both.

Examples
ends_of_line(["Mia", "Leo", "Ava"])→['Mia', 'Ava']
ends_of_line(["Sam"])→['Sam', 'Sam']
main.py
def ends_of_line(line):
    first = line[0]
    # your code here: the last person
    last = None
    return [first, last]
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.