0
cars = ["audi", "bmw", "ford", "tesla"]
print(cars.reverse())

The result is None.

newList=list(reverse_iterator)
print("reversed list is:",newList)

But when I do this the result is ['tesla', 'ford', 'bmw', 'audi'].

martineau
  • 119,623
  • 25
  • 170
  • 301
Alok Jha
  • 1
  • 1
  • 5
    `reverse()` modifies the list in place, it doesn't return the reversed list. Do `cars.reverse()` followed by `print(cars)` – Barmar Apr 01 '22 at 16:59
  • There's a function `reversed(cars)` that returns the reversed list instead of modifying in place. – Barmar Apr 01 '22 at 17:00
  • What is `reverse_iterator`? – Barmar Apr 01 '22 at 17:01
  • The question doesn't include code for creating `reverse_iterator` so that part isn't well-formed (letting others reproduce the problem themselves and be certain of their answers). The part that _is_ well-formed is a duplicate. – Charles Duffy Apr 01 '22 at 17:03
  • Always look at the docs when using functions you haven't played with before! See https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types "`s.reverse()` reverses the items of s in place" – flakes Apr 01 '22 at 17:03

0 Answers0