I'm trying to write a function that outputs the reverse of the input. I know that you can use the built-in list.reverse() or S[::-1] methods, but I want to make it using the 'for' loop. My code initially is:
def reverse(S) for x in S: print(x, end = " ")
the inputs would be
>>> reverse(['a','b','c'] ['a','b','c'] #this is output on shell
Any ideas on how to reverse it and have the output be like below:
>>> reverse(['a','b','c'] ['c','b','a']
Any help would be greatly appreciated. Thanks.