✅
실습 프로젝트 (Practice) · ★★
우선순위·마감일 + 정렬·필터
Lv2 · To-Do List
할 일 추가/조회/완료/삭제 + 우선순위·마감일을 갖춘 메모리 기반 할 일 관리. list 의 dict 컬렉션을 다룹니다.
dictlist정렬필터
소요 시간
⏱ 2~3시간
난이도
📊 자료구조 활용
선수 조건
🎯 기초 6-9주차
결과물
리스트의 dict 패턴과 명령어 파싱
이 강의에서 배우는 것
- 1할 일을 dict 로 표현하고 list 에 보관한다
- 2list 명령에 --pending, --sort priority 옵션을 단다
- 3번호로 done/del 을 정확히 처리한다
데이터 모델
python
[{"task": str, "done": bool, "priority": str, "due": str}, ...]명령
- add — 할 일/우선순위/마감일 입력
- list [--pending] [--sort priority]
- done <번호>
- del <번호>
- quit
도전 과제
- 마감 임박 강조
- 카테고리(태그)
채점 체크리스트
- 5개 명령 동작
- 옵션 처리
- 잘못된 번호 안전
💻 예제 (examples)
실제로 실행해 결과를 확인할 수 있는 예제 코드입니다.
solution.py— 전체 동작 코드
CODE
"""To-Do List — 우선순위·마감일 지원"""
PRIORITY_ORDER = {"높음": 0, "보통": 1, "낮음": 2}
todos = []
def add():
task = input("할 일: ").strip()
if not task: return
p = input("우선순위 (높음/보통/낮음, 기본 보통): ").strip() or "보통"
if p not in PRIORITY_ORDER:
p = "보통"
due = input("마감일 (YYYY-MM-DD, 없으면 엔터): ").strip()
todos.append({"task": task, "done": False, "priority": p, "due": due})
print("추가됨")
def show(args=""):
items = list(enumerate(todos, 1))
if "--pending" in args:
items = [(i, t) for i, t in items if not t["done"]]
if "--sort priority" in args:
items.sort(key=lambda x: PRIORITY_ORDER[x[1]["priority"]])
if not items:
print("(비어있음)"); return
for i, t in items:
mark = "[x]" if t["done"] else "[ ]"
due = f"~{t['due']}" if t["due"] else ""
print(f"{i}. {mark}[{t['priority']}] {t['task']} {due}".rstrip())
def main():
while True:
raw = input("\n> ").strip()
if not raw: continue
parts = raw.split(maxsplit=1)
cmd = parts[0]
arg = parts[1] if len(parts) > 1 else ""
if cmd == "quit": break
elif cmd == "add": add()
elif cmd == "list": show(arg)
elif cmd == "done":
try:
idx = int(arg) - 1
if 0 <= idx < len(todos):
todos[idx]["done"] = True
print("완료")
else:
print("번호 없음")
except ValueError:
print("번호를 입력하세요")
elif cmd == "del":
try:
idx = int(arg) - 1
if 0 <= idx < len(todos):
del todos[idx]
print("삭제")
except ValueError:
print("번호를 입력하세요")
else:
print("알 수 없는 명령")
if __name__ == "__main__":
main()▶ 실행 결과
> add
할 일: 우유 사기
우선순위: 높음
마감일: 2026-05-12
추가됨
> list
1. [ ][높음] 우유 사기 ~2026-05-12
> done 1
완료📝 과제 (exercises)
직접 풀어보고, 막힐 때 정답을 펼쳐 비교해보세요.
과제 1
프로젝트 구현
목표: 위 사양대로 직접 작성한다.
요구사항
- dict 리스트
- list/add/done/del/quit
- 옵션 처리
💡 힌트
enumerate(todos, 1) 로 번호 매기기
입출력 예시
1. [x][높음] 우유 사기채점
- · 5개 명령
- · 옵션 동작
▶정답 코드 펼치기 / 접기
SOLUTION
# 위 solution.py 와 동일▶ 실행 결과
(예제 참고)