Optimizing reading integers directly into a set without a list comprehension in Python I am reading space separated integers, removing redundant ones and then sorting them. The following code works.

I was thinking whether this is the fastest way to do that or can it be optimized more?

import sys

def p():
    #Reads space seperated integers
    #Removes redundant
    #Then sorts them
    nums = set(map(int,next(sys.stdin).split()))
    nums = [i for i in nums] -
    nums.sort()
    print nums


EDIT:

tobia_k's suggestion is better performance-wise. Just 1 sentence instead of 3 and better in time-efficiency.

nums = sorted([int(i) for i in set(next(sys.stdin).split())])
inpt = raw_input("Enter a string of numbers: ")
numbers = sorted(set(map(int, inpt.split())))
print numbers



I would recommend separating the input-reading from the integer-extraction part.
Using raw_input (Python 2.x) or input (Python 3) is more usual for reading user inputs.
You can do it all in one line using sorted instead of sort.
Performance-wise it might be better to apply set first, and then map, so int has to be applied to fewer elements, but I don't think it makes much of a difference, if at all.