Python

Reading strings

We can read a single line string using the built-in functions input():

1
a_line_read = input()

Reading an array of integers

When you need to read an array of integers, you have to read the entire line, split it and the convert each element to an int:

1
a_list_of_nums = map(int, input().split())

Reading n rows made up of a single integer

1
2
for n in range(10):
    single_int = map(int, input())

Writing on STDOUT

When you need to write on stdout use:

1
print("some text", file=sys.stdout)
comments powered by Disqus