Python dont return a new list when you work on methods of class list
, so is there a way to do one-liners in python without the use of list comprehension or lambda function?
For exemple, I cant do:
def foo():
return "Euston saw I was not Sue".split().reverse()
Because reverse dont return a new list, I need to assign "Euston saw I was not Sue".split()
to a variable and then apply reverse to this variable and then return a, like this:
def foo():
r = "Euston saw I was not Sue".split()
r.reverse()
return r
Is there a solution to do something like the first code?
Thanks.