15,849,616 members
See more:
sort the unsorted elements and square the elements in it

input:

-9 -2 0 2 3

output:

0 4 4 9 81

81 4 0 4 9

What I have tried:

Python
```l1 = list(map(int,input().split()))
l2 = sorted(l1)
for i in l2:
n = i**2
print(n,sep=" ")```
Posted
Updated 22-Feb-22 8:12am
v2
Richard MacCutchan 22-Feb-22 11:37am
What is the question?
CPallini 22-Feb-22 11:42am
It looks a working solution.
shri harshan 22-Feb-22 12:55pm
sorry forget to mention the error.

## Solution 1

Based on the requirements ("Sort the unsorted elements and square the elements in it"), the output you are getting is correct.
If you really wish to obtain a sorted list of squares, then you have first to generate a list of squares and then sort it.
Try
Python
```lin = list(map(int,input().split())) # original list
lsq = ([x*x for x in lin]) # list of squares
lsq = sorted(lsq)  # sorted list of squares

for sq in lsq:
print(sq, sep=" ")```

v2
Maciej Los 23-Feb-22 10:11am
5ed!
CPallini 23-Feb-22 10:30am
Thank you, Maciej!