[Python/Silver II] DFS와 BFS - 1260, 스택, 재귀함수, deque, queue
문제 설명그래프를 DFS로 탐색한 결과와 BFS로 탐색한 결과를 출력하는 프로그램을 작성하시오. 단, 방문할 수 있는 정점이 여러 개인 경우에는 정점 번호가 작은 것을 먼저 방문하고, 더 이상 방문할 수 있는 점이 없는 경우 종료한다. 정점 번호는 1번부터 N번까지이다. codeimport sysfrom collections import dequeinput = sys.stdin.readlinen, m, v = map(int, input().split())graph = [[] for _ in range(n+1)]for _ in range(m): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a)for i in ran..
[Python] append() vs. extend() 공통점과 차이점
한 눈에 보기 공통점append(), extend() 모두 목록의 끝에 무언가를 추가하는 메서드입니다. 차이점a list에 b list를 추가하고 싶을 때 어떤 메서드를 사용하느냐에 따라 결과는 상이합니다.append: ['apple', 'banana', 'cherry', ["Ford", "BMW", "Volvo"]]extend: ['apple', 'banana', 'cherry', 'Ford', 'BMW', 'Volvo'] append()The append() method appends an element to the end of the list.목록의 끝에 요소를 추가합니다.list.append(elmnt)ParameterDescriptionelmntRequired. An element of any ..