전체보기
-
(서브 폴더 포함) 전체 파일 해시 추출Python/이것저것 파이썬 2022. 10. 28. 09:57
[Q] 폴더와 파일 이름과 용량 등을 비교하여 파일 매칭을 해야하는데요. 네트워크로는 공유가 안되고 복사하기엔 용량이 너무 큰 상태입니다. ------------------------------- [A] 각 PC에서, 파일 패스, 파일 사이즈, 해시값을 출력한 뒤 이 값들을 비교하는 게 좋을 것 같습니다. 해시의 원리상 같은 파일일 경우 해시 값은 항상 같습니다. 다른 파일일 경우 해시 값이 같을 확률이 아주 약간 있습니다만, 파일 크기까지 비교한다면 그 확률을 더 줄일 수 있습니다. import os import hashlib def check_dir(path): for root, _, files in os.walk(path): for file in files: joined_path = os.path...
-
할인 행사코딩 테스트/Level 2 2022. 10. 28. 00:01
https://school.programmers.co.kr/learn/courses/30/lessons/131127 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(want, number, discount): answer = 0 to_buy = {a: b for a, b in zip(want, number)} for index in range(len(discount) - 9): temp = to_buy.copy() for each in discount[index:index + 10]: if each in temp: temp[each]..
-
프로그래머스 / 햄버거 만들기코딩 테스트/Level 1 2022. 10. 27. 23:25
https://school.programmers.co.kr/learn/courses/30/lessons/133502 파이썬 def solution(ingredient): stack = [] answer = 0 for each in ingredient: stack.append(each) if stack[-4:] == [1, 2, 3, 1]: answer += 1 del stack[-4:] return answer 코틀린 class Solution { fun solution(ingredient: IntArray): Int { var answer = 0 val bugger = listOf(1, 2, 3, 1) val stack = mutableListOf() for (each in ingredient) { s..
-
프로그래머스 / 옹알이 (2)코딩 테스트/Level 1 2022. 10. 27. 23:16
https://school.programmers.co.kr/learn/courses/30/lessons/133499 파이썬 def solution(babbling): answer = 0 for each in babbling: for index, text in enumerate(("aya", "ye", "woo", "ma")): each = each.replace(text, str(index)) if each.isdigit(): if '00' not in each: if '11' not in each: if '22' not in each: if '33' not in each: answer += 1 return answer 코틀린 class Solution { fun solution(babbling: Arr..
-
프로그래머스 / 콜라 문제코딩 테스트/Level 1 2022. 10. 27. 23:15
https://school.programmers.co.kr/learn/courses/30/lessons/132267 파이썬 def solution(a, b, n): answer = 0 while n >= a: quotient = n // a # 몫 new_bottle = quotient * b # 새 콜라 n -= a * quotient # 마트에 가져다 준 빈 병 answer += new_bottle n += new_bottle return answer import sys sys.setrecursionlimit(10000) def solution(a, b, n): if n < a: return 0 quotient = n // a new_bottle = quotient * b return new_bott..
-
프로그래머스 / 삼총사코딩 테스트/Level 1 2022. 10. 27. 23:14
https://school.programmers.co.kr/learn/courses/30/lessons/131705 파이썬 억지스럽게... from itertools import combinations solution = lambda number: sum(1 for each in combinations(number, 3) if sum(each) == 0) 정상적으로... from itertools import combinations def solution(number): return sum(1 for each in combinations(number, 3) if sum(each) == 0) 코틀린 class Solution { fun solution(number: IntArray): Int { var a..
-
프로그래머스 / 숫자 짝꿍코딩 테스트/Level 1 2022. 10. 27. 23:13
https://school.programmers.co.kr/learn/courses/30/lessons/131128 파이썬 억지스럽게... from collections import Counter solution = lambda num1, num2: ('0' if (result := ''.join(each * inter_n[each] for each in sorted(inter_n, reverse=True)))[0] == '0' else result) if (inter_n := Counter(list(num1)) & Counter(list(num2))) else "-1" 덜 억지스럽게... from collections import Counter def solution(num1, num2): return..
-
파이썬 초기 설정 저장 방식Python/이것저것 파이썬 2022. 10. 25. 13:20
저는 프로그램의 초기 설정들은 저장할 때, pickle을 많이 씁니다. 바이너리 파일이라 유저들이 수정하기 어렵고, 코드는 간결하죠. https://scshim.tistory.com/614 하지만 유저들이 수정하도록 열어두어야할 설정도 있습니다. 이럴 경우에는 ini, json, yaml, xml, toml, py 등을 사용합니다. 가장 많이 알려진 ini 같은 경우는 공식 문서(configparser - 구성 파일 구문 분석기)를 보는 것이 가장 좋습니다. https://docs.python.org/ko/3/library/configparser.html 전체적으론 이런 글을 참고해도 좋겠죠. https://emilkwak.github.io/python-setting-file-ext xml은 공식 문서를..