Python file objects are iterable. So we can apply the usual itertools
mix to them. What you've done with one line can be easily extended to several.
print(list(map(lambda x: len(set(re.findall('[^ \n]+', x))), sys.stdin)))
As was mentioned in the other answer, I suggest using some intermediate variables to make this prettier (doing so does not affect how functional your code is, provided you never mutate the variables)
def handle_line(x):
coll = set(re.findall('[^ \n]+', x))
return len(coll)
result = map(handle_line, sys.stdin)
print(list(result))
If you want to run once for the whole file, rather than running a separate iteration on each line, you can get the whole file like so.
# Be careful; this will DEFINITELY fail on large files
file_data = '\n'.join(list(sys.stdin))
Then you can run your len(set(...))
sequence of operations on the resulting string instead.