[PYTHON] HackerRank memo

HackerRank memo

It is a personal memo

Basic language

python3

Raw_input () Keyboard input (python2) input () for python3

n = input() n = int(input())

.Strip () Remove whitespace characters (spaces, tabs, newlines)

input().strip()

Sprit () Makes an array separated by the specified characters. If not specified in (), separate with a space or TAB

input().split()

STDIN Keyboard entered value Standard input

・ Difference Difference difference of the two numbers (first - second).

・ Product multiplication product of the two numbers.

・ ʻA // b` division. Returns the quotient as an integer Truncate after the decimal point

For statement for variable in sequence

n = int(raw_input())

for i in range(n):
   print(i*i)

・ ` Lange ` i<n from i = 0 n is not included.

range(3) = [0,1,2]

・ Leap Day leap year We add a Leap Day on February 29.

・ Intercalary day The day it was plugged in The leap day is an extra, or intercalary day.

・ Evenly divided by ~ Divisible by The year can be evenly divided by 4, is a leap year.

・ ʻIf statement` Required ":" after if, elif, else.

Sum (array) Calculate the total value

list = range(5)
print(sum(list)) 

Str () Convert to string

n = int(input())

a=""
for i in range(n):
   a =a+str(i+1)
print(a)

#output
a=12345~

・ Arithmetic operations Arithmetic operator. +-*%

・ Runner-up second place you are required to find the runner-up score.

(Lambda variable: processing) (argument) Lambda function You can create a function in one line (equivalent to def) (lambda variable: processing) (argument) └ Assign arguments to processing └ Multiple arguments are possible. Enter a variable in the ranking process.

print((lambda a,b,c:a*100+b*10+c*1)(1,2,3))

#output
123

Map (function, array) map function Execute a function for each element of the array. The output is a map object → Convert to list object with list (map ())

-Convert an array to an integer using the map function map = (int, array)

arr = map(int, input().split())

X ** y Exponentiation. x to the yth power

100 = 0 103 = 1000

Set () Remove duplicate values from array set type

arr=[2,3,6,6]
print(set(arr))

{2,3,6}

Sorted () Arrange the array in ascending order

Extract the nth largest value sorted()[-n]

#Extract the second largest value
arr=[2,3,6,6,5]

sorted(set(arr))[-2]

#output
5

・ Order their names alphabetically Arrange in alphabetical order order their names alphabetically and print each one on a new line.

Recommended Posts

HackerRank memo
gzip memo
Raspberry-pi memo
Python memo
python memo
graphene memo
Flask memo
pyenv memo
Matplotlib memo
pytest memo
sed memo
Python memo
Install Memo
BeautifulSoup4 memo
networkx memo
python memo
tomcat memo
command memo
Generator memo.
psycopg2 memo
Python memo
SSH memo
Command memo
Memo: rtl8812
pandas memo
Shell memo
Python memo
Pycharm memo
Python memo
AtCoder devotion memo (11/12)
[OpenCV] Personal memo
[Python] Memo dictionary
PyPI push memo
tensorflow-gpu introduction memo
LPIC304 virtualization memo
ALDA execution memo
python beginner memo (9.2-10)
youtube download memo
Linux x memo
Django Learning Memo
ARC # 016 Participation memo
Beautiful Soup memo
LPIC101 study memo
python beginner memo (9.1)
linux (ubuntu) memo
scp command memo
Flask Primer Memo
celery / kombu memo
who command memo
django tutorial memo
Flask basic memo
Linux # Command Memo 1
★ Memo ★ Python Iroha
Gender recognition memo
Image reading memo
[MEMO] [TERMINAL] Alacritty
3D rotation memo (1)
[Python] EDA memo
Python 3 operator memo
H2O.ai Introduction memo
lambda expression memo