I had a job interview today. During it I was asked to write down an algorithm that will reverse a list. First I offered the answer using the reversed() method:
I'm assuming your interviewer didn't want you to use built-in Python methods, but an algorithm that's more language-agnostic. Something like:
lst = [1,2,3,4,5] lst2 = [] while len(lst) > 0: lst2.append(lst.pop())
or
lst2 = [lst.pop() for _ in lst[:]]