reverse list in the python

Viewed 121

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?

3 Answers

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] 

ā€ā€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)

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

Related