Answer to Question #205368 in Python for ayushi

Question #205368

input:

1 20 3

30 10 2

5 11 15


output:

[[1, 2, 3], [5, 10, 11], [15, 20, 30]]


expected output:

1 2 3 
5 10 11 
15 20 30 
1
Expert's answer
2021-06-11T05:06:32-0400
inputLine1 = '1 20 3'
inputLine2 = '30 10 2'
inputLine3 = '5 11 15'

inputList = [inputLine1, inputLine2, inputLine3]

for i in range(len(inputList)):
    # Split input line into a list
    inputList[i] = inputList[i].split()
    # Convert each item in input line into integer
    inputList[i] = [int(item) for item in inputList[i]]

# List containing the elements of all lists in the input list
mergedInputList = []

for l in inputList:
    mergedInputList.extend(l)

mergedInputList.sort()

# Display output
for i in range(len(mergedInputList)):
    end = ' '
    if (i + 1) % 3 == 0:
        end = '\n'
    print(mergedInputList[i], end=end)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS