A reminder of what I got stuck when starting Atcoder with python

Input / output

Store integers in multiple variables

When storing an integer in multiple variables, store it with variable name A and variable name B = map (int, input (). Split ()).

input


1 2

Sample code


a,b=map(int,input().split())
print(a)
print(b)

Execution result


1
2

When storing an integer in a list, store it with list name = list (map (int, input (). Split ())).

input


1 2 3 4 5

Sample code


List=list(map(int,input().split()))
print(List)

Execution result


[1, 2, 3, 4, 5]

Store integers in list

When storing an integer in the list, store it with the list name = [int (input ()) for variable in range (number of variables)].

input


1
2
3
4
5

Sample code


List=[int(input()) for i in range(5)]
print(List)

Execution result


[1, 2, 3, 4, 5]

Store integers in a two-dimensional list

When storing an integer in a two-dimensional list, the list name = [list (map (int, input (). Split ())) for variable in range (number of input lines)].

input


3
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15

Sample code


Row=int(input())
List=[list(map(int,input().split())) for i in range(Row)]
print(List)

Execution result


[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]

Ternary operation

if / else statement

When the conditional expression is described by a ternary operation, it becomes print (processing where the conditional expression is TRUE if conditional expression else processing when the conditional expression is FALSE).

Sample code


a=1
print("a is 1" if a==1 else "a is not 1")

Execution result


a is 1

About slices

This article is easy to understand!

Recommended Posts

A reminder of what I got stuck when starting Atcoder with python
What I did when I got stuck in the time limit with lambda python
When I made CaboCha usable with python3, I got stuck (Windows 10)
I got stuck when trying to specify a relative path with relative_to () in python
What I did with a Python array
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
When I tried to introduce python3 to atom, I got stuck
I got a Value Error when using JUMAN ++ with PyKNP
What I got stuck around GUI in WSL python environment
I tried a stochastic simulation of a bingo game with Python
[Python] What is a with statement?
I made a fortune with Python.
A story that went missing when I specified a path starting with a tilde (~) in python open
I made a daemon with Python
When I got a list of study sessions in Python, I found something I wanted to make
I tried to create a list of prime numbers with python
I made a lot of files for RDP connection with Python
A note where a Python beginner got stuck
What I got into when using Tensorflow-gpu
I made a character counter with Python
I drew a heatmap with seaborn [Python]
What I got from Python Boot Camp
I tried a functional language with Python
[AtCoder] Solve ABC1 ~ 100 A problem with Python
Solve AtCoder ABC168 with python (A ~ D)
I made a Hex map with Python
"First Elasticsearch" starting with a python client
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
[AtCoder explanation] Control the A, B, C problems of ABC182 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC186 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC185 with Python!
I get a UnicodeDecodeError when trying to connect to oracle with python sqlalchemy
I got stuck in a flask application redirect with a reverse proxy in between
[AtCoder explanation] Control the A, B, C problems of ABC187 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC184 with Python!
When I cut the directory for UNIX Socket under / var / run with systemd, I got stuck in a pitfall and what to do
I got an error when saving with OpenCV
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I tried to make a simple mail sending application with tkinter of Python
[Python3] A story stuck with time zone conversion
[AtCoder explanation] Control the A, B, (C), D problems of ABC165 with Python!
I got an error when I put opencv in python3 with Raspberry Pi [Remedy]
[AtCoder explanation] Control the A, B, C, D problems of ABC183 with Python!
I failed when clustering with k-means, but what should I do (implementation of kernel k-means)
A story that turned light blue in 4 months after starting AtCoder with python
I want to make a game with Python
When I tried to create a virtual environment with Python, it didn't work
I failed to install django with pip, so a reminder of the solution
Solve A ~ D of yuki coder 247 with python
A story stuck with handling Python binary data
When I tried to connect with SSH, I got a warning about free space.
A memo when creating a python environment with miniconda
What Python beginners got hooked on with Django
What I did when updating from Python 2.6 to 2.7
[Question] What happens when I use% in python?
A note I was addicted to when running Python with Visual Studio Code
Challenge AtCoder (ABC) 164 with Python! A ~ C problem