본문 바로가기

Programming216

github 자체 CI, CD => action github action Workflow syntax for github actions 정말 간단함:: branch에 push나 pr이 있을 때 action이 trigged하게 할 수 있다. 위 문서만 봐도 쉽게 사용할 수 있다. /.github/workflows/python-app.yml 자동으로 생성된 yml # This workflow will install Python dependencies, run tests and lint with a single version of Python # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-action.. 2020. 7. 1.
python 에서 변수 비교하기 `==` or `is` python 의 ==, is 비교 == : 값을 비교 is : 메모리를 비교 >>> x,z = 1,1 >>> z == x True >>> z is x True >>> x,z = 300,300 >>> x == z True >>> x is z False 변수가 1 일때는 ==, is 모두 True 변수가 300 일때는 is는 False 파이썬은 정수 -5 ~ 256을 특정 메모리에 저장 해두고, 변수 생성시 참조를 통해 사용한다 그래서 300은 서로 다른 메모리를 참조해서 False가 된다 Buy me a coffee 2020. 6. 30.
문자열 거꾸로(reverse) 시키기 python에서 문자열 거꾸로 출력하기, 4가지 방법 reversed(), list.reverse(), [::-1], deque() # list.reverse(), source list가 바뀜 s = "abcdefg" s_list = list(s) s_list.reverse() print(s_list) ['g', 'f', 'e', 'd', 'c', 'b', 'a'] # reversed(), 뒤집힌 list를 반환함 s = "abcdefg" reversed_s_list = reversed(s) print(reversed_s_list) gfedcba # [::-1], 뒤집힌 list를 반환함 s = "abcdefg" reversed_s_list = s[::-1] print(reversed_s_list) gf.. 2020. 6. 29.
dict 에서 value max인 key, value값 찾기 dict 에서 value max인 key, key value 찾기 >>> d = {'b': 3, 'a': 2, 'c': 2} >>> max(d.values(), key=lambda k: d[k]) 2 >>> max(d.keys(), key=lambda k: d[k]) 'b' >>> max(d, key=lambda k: d[k]) 'b' >>> max(d.items(), key=lambda k: k[1]) ('b', 3) 2020. 6. 28.
Array(list)의 원소 개수 카운팅 collections 의 defaultdict로 배열의 엘러먼트 카운트를 하나의 함수도 대신하기 collections.Counter를 사용하면된다 from collections import defaultdict s = ['a', 'b', 'c', 'b', 'a', 'b', 'c'] dd = defaultdict(int) for k in s: dd[k]+=1 print(dd) defaultdict(, {'a': 2, 'b': 3, 'c': 2}) >>> from collections import Counter >>> d = Counter(s) >>> print(d) Counter({'b': 3, 'a': 2, 'c': 2}) 2020. 6. 27.
string을 원하는 width로 자르고 싶을때 python 내부 함수로 string을 원하는 width로 자르기 import textwrap result: List[str] = textwrap.wrap(string, max_width) >>> import textwrap >>> textwrap.wrap("abcdefghijklmn", 3) ['abc', 'def', 'ghi', 'jkl', 'mn'] 2020. 6. 26.