Algorithm problem solving/기본2 python 자료구조_stack 과 queue stack 나중에 넣은 데이터를 가장 먼저 꺼내 쓸 수 있도록 설계된 자료구조이다. 택배 상하차 를 생각해보자. (LIFO : Last In First Out) 주요기능은 push():맨 마지막에 데이터 삽입, pop():맨 마지막 데이터 꺼내기, peak():맨 마지막 데이터 확인, isEmpty():스택이 비어있나요? 가 있다. python에서는 pop(), append(), st[-1], len(st) 를 사용한다. arr = [1,2,3,4] st = [] for a in arr: st.append(a) print(st) // [1,2,3,4] print(st.pop()) // 4 print(st.pop()) // 3 print(st[-1]) // 2 print(True if st else Fal.. 2020. 8. 29. [python] collections.Counter Collections.Counter() A counter tool is provided to support convenient and rapid tallies. It is a collection where elements are stored as dictionary keys and their counts are stored as dictionary values. Counts are allowed to be any integer value including zero or negative counts. The Counter class is similar to bags or multisets in other languages. elements() c = counter(a=4, b=2, c=0, d=-2) so.. 2020. 8. 23. 이전 1 다음