
IT/파이썬 2021. 6. 15.
파이썬 - 여러개 값 관리 - 리스트, 튜플, 딕셔너리 멀 쓰나?
이거 할 때 마다 헷갈림 리스트, 튜플, 딕셔너리 비슷비슷한데 쩝... 여러개를 하나의 묶음으로 관리를 한다면 먼가 리스트 형태의 변수가 필요하다. 그냥 리스트만 알고 쓰면 좋은데 리스트 일단 대괄호로 만든다. [ ] 이렇게 말이다. 그냥 C에서 배열이라 생각하면 연계성이 생긴다. 추가, 삭제, 변경이 가능한데 아래 함수를 이용해서 해라 추가는 append() 삭제는 remove() https://velog.io/@inyong_pang/Python-List-Tuple-Dictionary-and-Set-%EC%9A%94%EC%95%BD List 함수 정리 append(원소) :리스트의 뒤쪽에 새로운 원소를 삽입 extend(리스트) : 리스트의 뒤쪽에 다른 리스트를 삽입 insert(인덱스, 원소) : 특..

IT/파이썬 2021. 6. 11.
파이썬 - dictionary 처리 관련해서, empty check, 추가하기
리스트 말고 딕셔너리 dictionary 타입 처리는 어떻게? 맨날 헷갈려서 그냥 적어두자. 비어있는지 체크하는 방법은 아래와 같다. https://stackoverflow.com/questions/23177439/python-checking-if-a-dictionary-is-empty-doesnt-seem-to-work test_dict = {} if not test_dict: print "Dict is Empty" if not bool(test_dict): print "Dict is Empty" if len(test_dict) == 0: print "Dict is Empty" 아이템 추가는 https://www.kite.com/python/answers/how-to-append-a-value-to-a..