방법
import itertools
list2d = [[1,2,3], [4,5,6], [7], [8,9]]
list(itertools.chain(*list2d))
# => [1, 2, 3, 4, 5, 6, 7, 8, 9]
import itertools
list2d = [[1,2,3], [4,5,6], [7], [8,9]]
list(itertools.chain(*list2d))
# => [1, 2, 3, 4, 5, 6, 7, 8, 9]
from datetime import datetime
from dateutil.relativedelta import relativedelta
# 2년 반 후
two_and_half_later = datetime.strptime("2023.01.01", "%Y.%m.%d") + relativedelta(years=2, months=6, days=-1)
print(two_and_half_later)
# => 2025-06-30 00:00:00
from datetime import datetime
str = "2023.10.08"
format = "%Y.%m.%d"
dt = datetime.strptime(str, format)
print(dt)
# => 2023-10-08 00:00:00
ascii_lowercase
사용ascii_uppercase
사용from string import ascii_lowercase
from string import ascii_uppercase
# 소문자 알파뱃 리스트
# => ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k …
값이 true인 프로퍼티는 값의 변경여부를 체크하도록 함
interface Props {
treeItem: Tree;
sameDepthTreeNames: Map<TreeType, string[]>;
setRootTree: Dispatch<SetStateAction<Tree>>
setMethodType: Dispatch<SetStateAction<MethodTypeForRecursivTreeItem>>
setMethodTargetTree: Dispatch<SetStateAction …
search_str = 'X'
two_dim_arr = [['O', 'O', 'O'], ['O', 'O', 'X'], ['O', 'O', 'O']]
answer=[(i, j) for i in range(len(two_dim_arr)) for j in range(len(two_dim_arr[0])) if two_dim_arr[i][j] == search_str][0]
print(answer)
# -> (1, 2)
search_str = 'X'
two_dim_arr = [['O', 'O', 'O …
one_dim_arr = ["abc", "def", "ghi"]
two_dim_arr = []
for p in one_dim_arr:
two_dim_arr.append(list(p))
print(two_dim_arr)
# -> [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]
one_dim_arr = ["abc", "def", "ghi"]
two_dim_arr = [list(row) for row in one_dim_arr]
print(two_dim_arr)
# -> [['a', 'b', 'c'], ['d', 'e', 'f'], ['g …
arr = ['a', 'b', 'c', 'd', 'e']
arr[0], arr[2] = arr[2], arr[0]
print(arr)
# -> ['c', 'b', 'a', 'd', 'e']