Skip to content

Instantly share code, notes, and snippets.

@aximov
Last active January 14, 2024 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aximov/0883b825de42cc7df1a89af8bb86ab91 to your computer and use it in GitHub Desktop.
Save aximov/0883b825de42cc7df1a89af8bb86ab91 to your computer and use it in GitHub Desktop.
# input
a = input() # str
a = int(input()) # int
a = list(input().split()) # list of str
a = list(map(int, input().split())) # list of int
n, m = list(map(int, input().split())) # pair of int
# output
print(a) # str, int
print(a, b) # multiple
print(*a) # spread list
# math
a ** b # power
# str / list
a = "ab"
b = "cd"
a + b # "abcd"
a * 3 # "ababab"
a.count("a") # 1
a = "abcd"
a[1:3] # "bc"
# str
a[1] = "a" # error, immutable
# list
a.append(1)
a.pop()
a * 3 # DO NOT USE, this is shallow copy
# ntuple
a = (1, 2, 3)
a[1] = 5 # error, immutable
# condition
0 <= a <= 10
a and b
a or b
not a
# immutable sequence
range(10) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
range(1, 11) # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
range(0, 30, 5) # [0, 5, 10, 15, 20, 25]
range(0, 10, 3) # [0, 3, 6, 9]
range(0, -10, -1) # [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
range(0) # []
range(1, 0) # []
# 隣接リストで表現した無向グラフ
graph: list[list[int]] = []
for _ in range(n):
graph.append([])
for _ in range(m):
u, v = map(int, input().split())
# 必要に応じて0-indexedにする
# u -= 1
# v -= 1
graph[u].append(v)
graph[v].append(u)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment