i have this question:
Write a function reverse3(nums) that takes a list of ints of length 3 called nums
and returns a new list with the elements in reverse order, so [1, 2, 3] becomes [3, 2, 1].
i solved it by:
def reverse3(nums):
return [nums[2]] + [nums[1]] + [nums[0]]
however, the answer is straight foward. My main question, how do i get nums
reversed, when i don't know how many ints there are in nums
?.
I've got this:
nums[::-1]
which does return nums
reversed.but i'm looking for a different way. probably looping?
Iv'e tried this:
def reverse3(nums):
return reversed(nums)
which returns: <list_reverseiterator object at 0x10151ff90>
#location?