-1

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
  • 5
    Does this answer your question? [How can I reverse a list in Python?](https://stackoverflow.com/questions/3940128/how-can-i-reverse-a-list-in-python) – Artemis Jul 28 '20 at 18:44
  • list(range(2, -5, -1)) would also be an option – Creepsy Jul 28 '20 at 18:46
  • It looks like you already know how to reverse a list. You can easily take what you know and do it in one line: `print(list(range(-4,3))[::-1])` – h0r53 Jul 28 '20 at 18:46

2 Answers2

1

Just combine all your lines in one:

print(list(range(-4,3))[::-1])

output

[2, 1, 0, -1, -2, -3, -4]
Jonas
  • 1,749
  • 1
  • 10
  • 18
0

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.

JimmyCarlos
  • 1,934
  • 1
  • 10
  • 24