[Python3] Standard input [Cheat sheet]

Premise

If you want to express it as an array of NumPy, it can be converted with np.array (), so it will be omitted.

NumPy array


l = [[1, 2, 3], [4, 5, 6]]
l = np.array(l)
# l = [[1 2 3][4 5 6]]

input code Remarks
a s = input()
1 s = int(input())
a b c s = list(input().split())
x, y, z = input().split()
1 2 3 n = list(map(int, input().split()))
x, y, z = input().split()
3
a
b
c
n = int(input())
l = [input() for i in range(n)]
3
1
2
3
n = int(input())
l = [int(input()) for i in range(n)]
2 3
a b c
d e f
n, m = map(int, input().split())
l = [list(input().split()) for i in range(n)]
---
n, m = map(int, input().split())
l = sum([list(input().split()) for i in range(n)], [])
Nested and flat format
2 3
1 2 3
4 5 6
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
---
n, m = map(int, input().split())
l = sum([list(map(int, input().split())) for i in range(n)], [])
3 2
1 a
2 b
3 c
n, m = map(int, input().split())
l = []
for i in range(n):
  x, y = input().split()
  l.append([int(x), y])
3
1 2 3 4
5 6 7 8
9 10 11 12
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
graph = {}
for i in range(n):
  graph.setdefault(str(l[i][0]), []).append(l[i][1:])
print(graph)
Get in graph format

Recommended Posts

[Python3] Standard input [Cheat sheet]
[Python] Standard input
Python3 cheat sheet (basic)
PySpark Cheat Sheet [Python]
Python sort cheat sheet
[Python] About standard input
Python3 standard input (competition pro)
Standard input / summary / python, ruby
Receiving standard input tips @ python
Data Science Cheat Sheet (Python)
Python Django Tutorial Cheat Sheet
Apache Beam Cheat Sheet [Python]
Python3 standard input for competitive programming
Matrix representation with Python standard input
Python cheat sheet (for C ++ experienced)
Python Computation Library Cheat Sheet ~ itertools ~
Python Paiza-Various skill checks and standard input
Python3 standard input I tried to summarize
Curry cheat sheet
Standard input summary
AtCoder cheat sheet in python (for myself)
Blender Python Mesh Data Access Cheat Sheet
Mathematical Optimization Modeler (PuLP) Cheat Sheet (Python)
SQLite3 cheat sheet
pyenv cheat sheet
Atcoder standard input set for beginners (python)
[Python] Add comments to standard input files
[Updating] Python Syntax cheat sheet for Java shop
Python: Use zipfile to unzip from standard input
Key input in Python
conda command cheat sheet
PIL / Pillow cheat sheet
Linux command cheat sheet
ps command cheat sheet
Spark API cheat sheet
python input and output
Python audio input / output
Memorize Python commentary 4 --Input
Go language cheat sheet
Key input in Python
Python pdf cheat sheets
Standard input / output summary
Have python parse the json entered from the standard input
[Python] Change standard input from keyboard to text file
Which is better, python standard input receiving input () or sys.stdin?
tox configuration file cheat sheet
Cisco Memorandum _ Python config input
numpy memory reuse cheat sheet
Write standard input in code
Standard input with time limit
Python standard unittest usage notes
Part 1 of receiving standard input
[For beginners] Summary of standard input in Python (with explanation)
Python Input Note in AtCoder
Slack API attachments cheat sheet
Transposed matrix in Python standard
[For AtCoder] Standard input memo
python standard virtual environment venv
[Python] How to use input ()
scikit learn algorithm cheat sheet
Python standard input summary that can be used in competition pro