This is because when you call:
set(sorted(A))
you are sorting the original full list and then filtering out the duplicate values. However, when you call:
sorted(set(A))
you are first shortening the list by removing duplicate values using set
and then sorting the much smaller list hence the shorter time.
Hope that makes sense.
For Example
>>> A = [1,2,3,1,2,3,1,2,3,1,2,3]
>>> A = sorted(A)
[1,1,1,1,2,2,2,2,3,3,3,3]
>>> set(A)
{1, 2, 3}
On the other hand:
>>> A = [3,2,1,3,2,1,3,2,1,3,2,1]
>>> A = set(A)
{3, 2, 1}
>>> sorted(A)
{1, 2, 3}
And as @Barmar said, sorting is much slower than removing duplicates therefore there is a real time gain when you have to sort a much smaller list (1/4 of the list in my example above)
Time Benchmarking
a = [1,2,3] * 10000
set(sorted(a)) --> 0.1890001297
sorted(set(a)) --> 0.0079998970