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)
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]
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
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?
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)
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]
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