0

I am currently working on POC on Alibaba Cloud and not authorized to share the information. I am a beginner in python. Let me consider an example to address my issue.

I am getting none instead of list of values,

Example code:

NumSet={1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet).reverse()
print(NumList)

Output:

None

What I am missing?

aristotll
  • 8,694
  • 6
  • 33
  • 53

2 Answers2

3

list.reverse() reverses the list in-place and returns nothing (or returns None).

NumList = list(NumSet)  # convert to list first
NumList.reverse()  # reverse in-place

This is the correct way to do it.

iBug
  • 35,554
  • 7
  • 89
  • 134
0

list.reverse() doesn't return the list reversed. What it does is reversing the list in-place. Just change to this and it ill work

NumSet = {1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet)
NumList.reverse()
print(NumList)
Birivera
  • 37
  • 8