본문 바로가기

[스파르타코딩클럽]데이터분석 과정/PYTHON29

[Python 코드카타] 58 ~ 60번 (프로그래머스) 58번 소수 만들기 def solution(nums): answer = 0 n = len(nums) # 1) 3개의 숫자를 꺼내서 합하기 for i in range(n-2): for j in range(i+1,n-1): for k in range(j+1, n): a = nums[i] + nums[j] + nums[k] # 2) 소수인지 아닌지 판별하기 b = True for l in range(2,int(a/2+1)): if a%l == 0: b = False break if b == True : answer += 1 return answer > combinations 라이브러리 활용과 for - else문 이해 def solution(nums): from itertools import combinati.. 2024. 1. 24.
[Python 코드카타] 55 ~ 57번 (프로그래머스) 55번 카드뭉치 > 처음에 런타임 에러 문제가 있었는데 - cards1이 먼저 null값이 될 경우를 생각하지 못함 ( cards1 != []를 안 넣고 돌려서 오류) def solution(cards1, cards2, goal): answer = '' while goal != []: if cards1 != [] and cards1[0] == goal[0]: cards1.pop(0) goal.pop(0) elif cards2 != [] and cards2[0] == goal[0]: cards2.pop(0) goal.pop(0) else : answer = 'No' break if goal == [] : answer = 'Yes' return answer > 깔끔한 답 def solution(cards1,.. 2024. 1. 23.
[Python 코드카타] 52 ~ 54번(프로그래머스) 52번 콜라 문제 def solution(a, b, n): answer = 0 while n >= a : # 3) n이 a보다 작을 때까지 반복 answer += (n//a)*b # 1) n = (n//a)*b + (n&a) # 2) return answer > 다른 풀이 우와.. 👏👏 풀이 이해하기도 어려움.. solution = lambda a, b, n: (n - b) // (a - b) * b # 1) a개를 주면 b개를 받아서 (a-b) # 2) 1번 실행할 때, b개를 받아서 n - b (솔직히 이해가 잘 안되는 부분..!) # 3) 횟수마다 b개씩 받기 때문에 *b > 오..신박한 답 def solution(a, b, n): answer = 0 while n >= a: n -= a answe.. 2024. 1. 22.
[Python][matplotlib](3) 그래프 꾸미기 1.컬러맵 설정하기 > plt. - spring(), summer(), autumn(), winter(), viridis(), plasma(), jet(), nipy_spectral() 2. 컬러바 설정하기 > plt.colorbar() 3. 텍스트 삽입 > text(x, y, ' text', fontdict = {}, bbox = {}) 4. 그래프 스타일 > plt.style.use() - 'default', ‘bmh’, ‘ggplot’, ‘classic’, ‘Solarize_Light2’ > plt.rcParams[ ] - 'font.size' , 'figure,figsize', 'family.font', 'lines.linestyle' 등 5. 그래프 저장할 때, 꾸미기 > dpi : 해상도 / .. 2024. 1. 20.
[Python][matplotlib] 선 종류, 색깔, 마커표시 기본 정리 1. 선 종류 2. 선 색깔 다양한 색상 : https://matplotlib.org/stable/gallery/color/named_colors.html 3. 마커 표시 2024. 1. 20.
[Python][matplotlib](2) 다양한 그래프 유형 [참고] 파이썬으로 데이터 시각화하기 (16 ~ 24장) 1. 막대 그래프 plt.bar(years, values, color = 'c', width=0.4) 2. 수평 막대 그래프 plt.barh(years, values, color = 'c', height = 0.3) 3. 산점도 그리기 > s : size / c : color / alpha : 투명도 / cmap : colormap import matplotlib.pyplot as plt import numpy as np np.random.seed(0) n = 50 x = np.random.rand(n) y = np.random.rand(n) area = (30 * np.random.rand(n))**2 colors = np.random.rand(.. 2024. 1. 20.