0

I don't know how to read input array number in input.txt and write result in output.txt. Example:

input.txt have array 7 8 9 2 
write result sort in output.txt 2 7 8 9  

How can I do it?

1
  • " input.txt have array 7 8 9 2" is no useful information. What is that to be, different lines? Data within the same line? Commented Apr 22, 2013 at 3:17

1 Answer 1

1

Suppose input is in input.txt and you want output in output.txt. Make a python script and name it sort.py like this:

l=map(int,raw_input("").strip().split())
l.sort() 
print l  # It will store it as a list

# or more precisely your answer can be
k=""
for i in l:
    k+=str(i)+" "
print k       #same output as you want

Run it in the terminal :

python sort.py < input.txt > output.txt

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.