0

Input

4
2 4 5 9
4
2 4 11 12

Output

11 
12 
5 
9

Expected output

5
9
11
12

I was expecting the list to be sorted but it is getting sorted according to the sets , even after it was converted from the set to a list.

Code

m = int(input())
minp=input().split()
n = int(input())
ninp=input().split()
a,b=set(minp),set(ninp)
set3=list(b.difference(a).union(a.difference(b)))
set3.sort()
for i in set3:
    print(i)

1 Answer 1

2

set3 contains strings, so sort is sorting the strings lexicographically.

Convert the Strings to numbers first before sorting:

set3 = [int(n) for n in set3]
set3.sort()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.