Question: In python, i have a .txt file that has rows of numbers. For example: I need to import this file above .txt file and sort

In python, i have a .txt file that has rows of numbers. For example:

In python, i have a .txt file that has rows of numbers.

I need to import this file above .txt file and sort the integers in each row. The problem I now have is that the integers in the rows arent being sorted and I need them to be, just the rows themselves are being sorted right now as shown below.

For example: I need to import this file above .txt file and

This is the code I have from the sort (geeksforgeeks):

sort the integers in each row. The problem I now have is

that the integers in the rows arent being sorted and I need

Also if possible, I would like to know how to remove the first number from each row and only sort everything from position [1] and larger only. So 4 19 2 5 11 would only sort 19 2 5 11.

1 2 3 4 14 192511 812345612 50 -537-2 1234 New Line 50 -5 3 7 -2 New Line 1 2 3 4 This is array : [['4', '19', '2', '5', '11'], ['8', '1', '2', '3', '4', '5', '6', '1', '2'], ['5', '0', '-5', '3', '7', '-2'], ['1', '2', '3', '4'1] Given array is 4 19 2 5 11 8 1 2 3 4 5 6 1 2 50 -5 3 7 -2 1 2 3 4 Sorted array is: 1 2 3 4 4 19 2 5 11 5 0 -5 3 7 -2 8 1 2 3 4 5 6 1 2 def mergeSort(arr): for i in range(len(arr)): #loop for j in range(len(arr[i])): #loop arr[i][j]=int(arr[i][j]) #converting str to int if len(arr) > 1: # Finding the mid of the array mid = len(arr) // 2 # Dividing the array elements L = arr[:mid] # into 2 halves R = arr[mid:] # Sorting the first half mergeSort(L) # Sorting the second half mergeSort(R) i = j = k = 0 # Copy data to temp arrays L[] and R[] while i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!