dir 내장 함수를 사용하면, 각 객체의 메소드를 알아낼 수 있다.
a = list()
print(dir(a))
['__add__', '__class__', '__class_getitem__', '__contains__',
'__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__',
'__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__',
'__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__',
'__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__',
'__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend',
'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
이렇게 갑자기 메소드를 까먹었을 때, 유용하다.
input은 시간 초과가 날 수도 있다.input() 대신 sys.stdin.readline()으로 대체하는 것이 좋다import sys
L, C = map(int, sys.stdin.readline().split())
from collections import Counter
counter = Counter("hello")
counter["l"] >> 2
counter["o"] >> 1
from itertools import combinations
temp_list = list(combinations(["a","b","c"], 2))
from itertools import permutations
temp_list = list(permutations(["a","b","c"], 2))
from itertools import product
temp_list = list(product(["a","b","c"], ["a","b","c"]))
temp_list = list(product(["a","b","c"], repeat=2))
A = [1,2,3,4,5]
print(A) # [1,2,3,4,5]
print(*A) # 1 2 3 4 5
T = "hi"
r = reversed(T)
T = ''.join(r).strip()
answer = "hi"
answer.upper() # HI
answer.lower() # hi
앞 뒤의 공백이나 문자를 제거
answer = " hi "
answer.strip() #hi
answer = 'aaaaaabb'
answer.rstrip('a') #bb
list = [[1,2],[4,3],[2,1]]
list.sort(key = lambda x : x[0]) # 앞 element 기준으로 정렬