Q:

Reverse a list in Python

belongs to collection: Python List Exercises

0

Reverse a list in Python

Given:

list1 = [100, 200, 300, 400, 500]

Expected output:

[500, 400, 300, 200, 100]

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

Use the list function reverse()

Solution1:list function reverse()

list1 = [100, 200, 300, 400, 500]
list1.reverse()
print(list1)

Solution2:Using negative slicing

-1 indicates to start from the last item.

list1 = [100, 200, 300, 400, 500]
list1 = list1[::-1]
print(list1)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a python program to add two lists index-wise... >>