I have to get this output: [2, 1, 0, -1, -2, -3, -4]
i tried this approach but our teacher wants the answer in one liner.
x=list(range(-4,3))
y=x[::-1]
y
I have to get this output: [2, 1, 0, -1, -2, -3, -4]
i tried this approach but our teacher wants the answer in one liner.
x=list(range(-4,3))
y=x[::-1]
y
Just combine all your lines in one:
print(list(range(-4,3))[::-1])
output
[2, 1, 0, -1, -2, -3, -4]
2 ways to do this:
print(list(range(-4,3))[::-1])
print(list(range(2,-3,-1)))
It's really good though that you're trying things and have the humility to ask for help when you're stuck. Teacher will be proud of you.