A blog on Python with tutorials, code, programs, tips and tricks, how-to, book-list, crawler / spider help, data structure and algorithm implementation and many more ...
I am looking for faster way for taking input from stdin in Python. So far I found three methods. input() - which is suitable for integers, raw_input() - reads the input as string and another one is sys.stdin.readline(). So far I have found sys.stdin.readline() is the fastest. Do you have any idea to read input (from console) in Python which is faster?
6 comments:
Another way to take console input:
import sys
for line in sys.stdin:
# do whatever you want with line
Note that there is an extra newline character ("\n") after end of each line.
The first line contains the number of test cases T. T lines follow, one corresponding to each test case, containing 3 integers : N, A and D.
SAMPLE INPUT
3
1 1 1
3 5 6
2 1 2
how to take this input??
t = int(raw_input())
while t:
t = t - 1
s = raw_input()
n, a, d = s.split()
n = int(n)
a = int(a)
d = int (d)
All the lines after while loop are inside while loop. Can't find any way to format it.
combining these lines in one:
n, a, d = [int(x) for x in raw_input().split()]
leading dots can be used to keep correct format.
while t:
....t = t - 1
....s = raw_input()
....n, a, d = s.split()
Post a Comment