Good Input Template for Python Users for Quick and Fast Inputs

Правка en2, от thekushalghosh, 2019-12-04 03:31:19

Hello Codeforces Community,

Actually all of the Python users over here would agree that "sometimes" we need to write a bit long for taking input in Python, and it is also slow.

That's why I made a good template for taking Quick And Fast Input, which I would like to share.

import sys
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

Just paste this template at the beginning of your Code.

It comprises of 4 functions :-

1) inp — For taking integer inputs.

2) inlt — For taking List inputs.

3) insr — For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.

4) invr — For taking space seperated integer variable inputs.

The input = sys.stdin.readline is actually for Faster Inputs, because line reading through System STDIN (Standard Input) is faster in Python.

Теги #python, input, fast input, #python3

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский thekushalghosh 2019-12-04 03:31:19 17 Tiny change: 'tem STDIN is faster' -> 'tem STDIN (Standard Input) is faster'
en1 Английский thekushalghosh 2019-12-02 23:46:51 1266 Initial revision (published)