Question

In: Computer Science

reverse_number_in_list(number_list:list)-> list This function will be given a list of numbers your job is to reverse...

reverse_number_in_list(number_list:list)-> list


This function will be given a list of numbers your job is to reverse all the numbers in the list and return a list with the reversed numbers. If a number ends with 0 you need to remove all the trailing zeros before reversing the number. An example of reversing numbers with trailing zeros: 10 -> 1, 590 -> 95. None of the numbers in the number_list will be less than 1.

Example:

number_list = [13, 45, 690, 57]

output = [31, 54, 96, 75]

Solutions

Expert Solution

Please look at my code and in case of indentation issues check the screenshots.

------------main.py-----------------


def reverse_number_in_list(number_list):
   output_list = []                               #output list
   for number in number_list:                       #read each number from the input list
       numberString = str(number)                   #convert number into string
       reverseNumberString = numberString[::-1]   #reverse the string
       reverseNumber = int(reverseNumberString)   #convert string to number
       output_list.append(reverseNumber)           #append number to the output_list
   return output_list                               #return the output list

#Test case 1
List1 = [13, 45, 690, 57]
print("Input: ", List1)
print("Reverse: ", reverse_number_in_list(List1))

#Test case 2
List2 = [23000, 4539, 80000]
print("\nInput: ", List2)
print("Reverse: ", reverse_number_in_list(List2))

--------------Screenshots-------------------

----------------------Output------------------------------------

-------------------------------------------------------------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs down.
Please Do comment if you need any clarification.
I will surely help you.

Thankyou


Related Solutions

The language is C++ Below are a list of sequences of numbers. Your job is to...
The language is C++ Below are a list of sequences of numbers. Your job is to program each sequence with any loop of your preference (while, for, do/while). I want the code to output the sequence provided and the next number in the sequence (you can output more but there is 1 sequence that may only have 1 number after).. Please order and notate each sequence in your output –. The output should also be horizontal like that shown below...
DO THIS IN C++: Question: Write a function “reverse” in your queue class (Codes are given...
DO THIS IN C++: Question: Write a function “reverse” in your queue class (Codes are given below. Use and modify them) that reverses the whole queue. In your driver file (main.cpp), create an integer queue, push some values in it, call the reverse function to reverse the queue and then print the queue. NOTE: A humble request, please don't just copy and paste the answer from chegg. I need more specific answer. Also I don't have much question remaining to...
haskell : write a function that reverse the first three element of a list, but not...
haskell : write a function that reverse the first three element of a list, but not the rest. example [1,2,3,4,5,6] == [3,2,1,4,5,6]
Write a Python function which finds the smallest even and odd numbers in a given list....
Write a Python function which finds the smallest even and odd numbers in a given list. (Use for loop and if conditions for this problem)
8.26 LAB: Output numbers in reverse Write a program that reads a list of integers, and...
8.26 LAB: Output numbers in reverse Write a program that reads a list of integers, and outputs those integers in reverse. The input begins with an integer indicating the number of integers that follow. For coding simplicity, follow each output integer by a space, including the last one. Assume that the list will always contain fewer than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: 10 8 6 4 2 To achieve...
Task 1: [10 Marks] Write a function “reverse” in your queue class (linked list implementation) that...
Task 1: [10 Marks] Write a function “reverse” in your queue class (linked list implementation) that reverses the whole queue. In your driver file (main.cpp), create an integer queue, push some values in it, call the reverse function to reverse the queue and then print the queue.
Javascript Problem: List Reverse Given a list: var list = { value: 1, next: { value:...
Javascript Problem: List Reverse Given a list: var list = { value: 1, next: { value: 2, next: { value: 3, next: null } } }; Reverse the order of the list so that it looks like: var list = { value: 3, next: { value: 2, next: { value: 1, next: null } } }; Use the following shell if needed: //assignment1.js function reverseList(list) { // your code here ... return reversedList; } Example Test Case(s): Arguments: { value:...
/* print_reverse function that prints the nodes in reverse order if the list is empty print...
/* print_reverse function that prints the nodes in reverse order if the list is empty print nothing */ include <bits/stdc++.h> using namespace std; class Node{     public:     int data;     Node *next;     Node *prev;     Node(int d, Node *p=NULL, Node *n=NULL){         data = d;         prev = p;         next = n;     } }; class DLL{     public:     Node *head;     DLL(){head=NULL;}     void push(int d){         Node *pNode = new Node(d,NULL,head);         if (head != NULL)             head->prev = pNode;         head = pNode;     }     void print_forward(){         Node *pCurr = head;...
In C++, Write a function to reverse the nodes in a linked list. You should not...
In C++, Write a function to reverse the nodes in a linked list. You should not create new nodes when you reverse the the linked list. The function prototype:          void reverse(Node*& head); Use the following Node definition: struct Node {    int data;    Node *next; }
Write a function that will accept a list of numbers and an integer (n). The function...
Write a function that will accept a list of numbers and an integer (n). The function should return a list containing every nth item from the input list, always starting with the first item in the list. The original list should not be modified. For example, if the function is passed the list [8, 3, 19, 26, 32, 12, 3, 7, 21, 16] and the integer 3, it will return the list [8, 26, 3, 16] If the function is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT