reverse list in the python

Question:

I’m trying to reverse a integer and using the below code but the resultant list value in None. How much can we put in a list? , The code:

int_a= [1,2,3,4,5,6]
rev_word = int_a.split()
rev_number = rev_number.reverse()
rev_number= "".join(rev)

it return the TypeError. Why?

Answers:

‍‍reverse() method, reverses list inplace. This means that rev_number.reverse() returns None.

So you can have a reversed list in this way:

int_a= "This is integer"
rev_word = int_a.split()
rev_word.reverse()
rev_number= "".join(rev_word)
Answered By: Amin

Here is the short and optimal way to reverse a list in python:

int_a= [1,2,3,4,5,6]
int_a = int_a[::-1] 
Answered By: Muhammad Abbas

int_a = [1,2,3,4,5,6]
int-a = int_a[::-1]

this answer is a mark for best answer for reverse list in the python.
try ite

Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.