I'm trying to define a new function called new_f, just for practice:
The purpose of function is:
x = ['1', '2', '3', '4']
y = new_f(x)
print(y)
And that should give:
['4', '3', '2', '1']
So it's a reverse of x.
I tried something like this:
def new_f(x):
y = len(x)
for z in range(y-1,-1,-1):
r = print([x[z]])
return r
But that gives:
['4']
['3']
['2']
['1']
Ok, that's not what I want, so maybe:
---------
for z in range(y-1,-1,-1):
r = [x[z]]
return r
And I get:
['1']
So he goes through all z and gives me the last one.
How can I resolve this problem?
Thanks in advance.
list[::-1]for z in range(y-1,-1,-1)loop iterating on?list[::-1]means you've masked the built-in functionlist()with a reference to an object of typelist.