array = [7, 5, 9, 0, 3, 1, 6, 2, 9, 1, 4, 8, 0, 5, 2]count = [0] * (max(array) + 1)for i in range(len(array)): count[array[i]] += 1for i in range(len(count)): for j in range(count[i]): print(i, end=' ')
전체 글
array = [5, 7, 9, 0, 3, 1, 6, 2, 4, 8]def quick_sort(array): if len(array) pivot] return quick_sort(left_side) + [pivot] + quick_sort(right_side)print(quick_sort(array))
array = [7, 5, 9, 0, 3, 1, 6, 2, 4, 8]for i in range(1, len(array)): for j in range(i, 0, -1): if array[j]
array = [7, 5, 9, 0, 3, 1, 6, 2, 4, 8]for i in range(len(array)): min_index = i for j in range(i + 1, len(array)): if array[min_index] > array[j]: min_index = j array[i], array[min_index] = array[min_index], array[i]print(array)
import redef isPallindrome(s : str) -> bool: s= s.lower() print(s) s= re.sub('[^a-z0-9]','',s) print(s) return s == s[::-1]print(isPallindrome("race A car"))# race a car# raceacar# False
alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd' ]alpha = list(set(alpha))print(alpha)
import reparagraph = "Bob hit a ball, the hit BALL flew far after ir was hit."banned = ['hit']# 단어 문자 아닌 것은 ' ' (공백으로 치환) 하고 소문자로 변경후 , banned가 아닌 것이 리스트로 반환words = [ word for word in re.sub(r'[^\w]', ' ', paragraph).lower().split() if word not in banned]print(words)
letters = ['let1 art can','let2 own kit dig', 'let3 art zero']#2번째 절을 정렬, 같을경우 맨앞 기준으로 정렬print(letters[1].split()[1:])letters.sort(key=lambda x : (x.split()[1:], x.split()[0]))print(letters)letters.sort(key=lambda x : (x.split()[1:], x.split()[0]),reverse=True)print(letters)
from collections import dequedef bfs(graph, start, visited): queue = deque([start]) visited[start] = True while queue: v = queue.popleft() print(v, end=" ") for i in graph[v]: if not visited[i]: queue.append(i) visited[i] = True#각 노드 번호에 연결 되어 있는 노드의 숫자graph = [ [], [2, 3, 8], [1, 7], [1, 4, 5], [3, 5], [3, ..
def dfs(graph, v, visited): visited[v] = True print(v, end = ' ') for i in graph[v]: if not visited[i]: dfs(graph, i, visited)# 각 노드 번호에 연결 되어 있는 노드의 숫자graph = [ [], [2, 3, 8], [1, 7], [1, 4, 5], [3, 5], [3, 4], [7], [2, 6, 8], [1, 7]]# 정렬이 안되어 있으면 정렬이 필요함for i in graph: i.sort() visited = [False] * 9dfs(graph, 1, visited)