while learning Python at pyschools, I got stuck at question 2.13.
I am asked to add the first and last numbers in a list. This is what I came up with:
return x + x[-1]
You need to check if your list is empty or not.
def addFirstAndLast(x): return (x + x[-1]) if x else 0