Python3 standard input I tried to summarize

Introduction

Since I recently started competitive programming, I have summarized the unexpectedly annoying standard input. I will fix the output and other processing later.

Input speedup

Speeding up


import sys
input = sys.stdin.readline

Simple input

input


apple
orange 
10
12.5
a = input()
b = str(input())
c = int(input())
d = float(input())

List type

input


1
2
3
4
5
X = [int(input()) for i in range(5)]
print(X)

output


[1, 2, 3, 4, 5]

input


1 2 3 4 5
A = list(map(int,input().split()))
print(A)

output


[1, 2, 3, 4, 5]

List in 〇〇

List in tuple

l = []
n = int(input())
for i in range(n):
    a,b=input().split()
    l.append((int(a), b))

List in list(int)

n = int(input())
arr = []
for i in range(n):
    arr.append(list(map(int, input().rstrip().split())))

List in list(str)

N = int(input()) 
arr = [list(map(str, input().split())) for i in range(N)]

Recommended Posts

Python3 standard input I tried to summarize
I tried to summarize Python exception handling
I tried to summarize SparseMatrix
I tried to summarize how to use matplotlib of python
I tried to summarize how to use pandas in python
I tried to summarize the string operations of Python
I tried to touch Python (installation)
[Python] Standard input
I tried to implement PLSA in Python
I tried to summarize the umask command
I tried to implement permutation in Python
I tried to implement PLSA in Python 2
I tried to summarize the graphical modeling.
I tried to implement ADALINE in Python
I tried to implement PPO in Python
Mayungo's Python Learning Episode 8: I tried input
[Python] I tried to calculate TF-IDF steadily
I tried to touch Python (basic syntax)
[Python] Add comments to standard input files
I tried to summarize Ansible modules-Linux edition
I tried to summarize everyone's remarks on slack with wordcloud (Python)
I tried Python> autopep8
I tried to debug.
I tried to paste
[Python] About standard input
I tried Python> decorator
I tried to get CloudWatch data with Python
I tried to output LLVM IR with Python
I tried to implement TOPIC MODEL in Python
I tried to automate sushi making with python
I tried to implement selection sort in python
LeetCode I tried to summarize the simple ones
Python: Use zipfile to unzip from standard input
[Python] I tried to summarize the set type (set) in an easy-to-understand manner.
I tried to streamline the standard role of new employees with Python
I tried fp-growth with python
I tried scraping with Python
I tried to graph the packages installed in Python
When I tried to introduce python3 to atom, I got stuck
I tried to learn PredNet
I tried to summarize the basic form of GPLVM
[Python3] Standard input [Cheat sheet]
I tried to implement Minesweeper on terminal with python
I tried to get started with blender python script_Part 01
I tried to touch the CSV file with Python
I tried to draw a route map with Python
I tried to organize SVM.
I tried to solve the soma cube with python
Python3 standard input (competition pro)
I tried to implement a pseudo pachislot in Python
Standard input / summary / python, ruby
Continuation ・ I tried to make Slackbot after studying Python3
Receiving standard input tips @ python
I tried to implement PCANet
I tried to get started with blender python script_Part 02
I tried to implement Dragon Quest poker in Python
I tried to implement an artificial perceptron with python
[Python] Change standard input from keyboard to text file
I tried to implement GA (genetic algorithm) in Python
I tried to summarize four neural network optimization methods
[Python] I tried to graph the top 10 eyeshadow rankings