In this Python list program, we will take a user input as a list and reverse all the numbers in a given list with the help of the below-given steps.
Reverse all the numbers in a list:
Steps to solve the program
- Take a list as input and create an empty list.
- Calculate the reverse of each number from the given list using for and while loop.
- Add the reverse number to the empty list.
- Print the list to see the result.
#Input lists
list1 = [123, 145, 633, 654, 254]
reverse_list = []
#Calculating reverse number
for value in list1:
reverse = 0
while value != 0:
digit = value%10
reverse = reverse*10 + digit
value //= 10
reverse_list.append(reverse)
#Printing output
print(reverse_list)
Output :
[321, 541, 336, 456, 452]
Related Articles
Python program to get palindrome numbers from a given list.
Python program to get a count of vowels in the given list.
Python program to get the list of prime numbers in a given list.
Python program to get a list with n elements removed from the left and right.
Python program to create a dictionary with two lists.
Python program to remove the duplicate item from the list using set.