본문 바로가기

DEV/PYTHON

데이터 구조 #2

스택(stack)의 리스트
>>> stack = [1, 2, 3]
>>> stack.append(4)
>>> stack.append(5)
>>> stack
[1, 2, 3, 4, 5]
>>> stack.pop()
5
>>> stack
[1, 2, 3, 4]
>>> stack.pop()
4
>>> stack.pop()
3
>>> stack
[1, 2]
--------------------------------------------------------------------------
큐(queue)리스트
>>> from collections import deque   #popleft를 사용하기 위해추가
>>> queue = deque(["김", "이", "최"])
>>> queue.append("강")           # Terry arrives
>>> queue.append("전")          # Graham arrives
>>> queue.popleft()                 # The first to arrive now leaves
'김'
>>> queue.popleft()                 # The second to arrive now leaves
'이'
>>> queue                           # Remaining queue in order of arrival
deque(['최', '강', '전'])
--------------------------------------------------------------------------
함수(Function) 프로그래밍
>>> def f(x):                  #함수정의
...     return x % 5 = 0       #5의 배수인것을 리턴
>>> filter(f,range(1,20))
36: [5, 10, 15]

'DEV > PYTHON' 카테고리의 다른 글

날로 먹는 Django 웹 프로그래밍 강좌  (0) 2012.01.18
WingWare Python IDE  (0) 2012.01.17
python 한글  (0) 2012.01.16
데이터 구조 #1  (0) 2012.01.10
os module  (0) 2012.01.04