0 votes
1 view
in Python by (44.3k points)
Can anyone tell me how to reverse a list in Python?

1 Answer

0 votes
by (95.5k points)

In Python, there are two ways of reversing a list. The first method is using a built-in function, reverse(). Refer to the below code:

lst = [10, 11, 12, 13, 14, 15]

lst.reverse() 

Lst

The second way is also a built-in function, reversed(). Refer to the below code:

def Reverse(lst): 

    return [ele for ele in reversed(lst)] 

lst = [1,3,7,5,9,40,34] 

print(Reverse(lst))

If you are looking for an online course to learn Python, I recommend this Python Course by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Oct 14, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
asked Jul 3, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
asked Jul 2, 2019 in Python by Anurag (33.2k points)
0 votes
1 answer
asked Jul 18, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...