본문 바로가기

Python345

0826. A wolf in sheep's clothing Wolves have been reintroduced to Great Britain. You are a sheep farmer, and are now plagued by wolves which pretend to be sheep. Fortunately, you are good at spotting them. Warn the sheep in front of the wolf that it is about to be eaten. Remember that you are standing at the front of the queue which is at the end of the array: [sheep, sheep, sheep, sheep, sheep, wolf, sheep, sheep] (YOU ARE HER.. 2022. 8. 26.
0825. Find the first non-consecutive number Your task is to find the first element of an array that is not consecutive. By not consecutive we mean not exactly 1 larger than the previous element of the array. E.g. If we have an array [1,2,3,4,6,7,8] then 1 then 2 then 3 then 4 are all consecutive but 6 is not, so that's the first non-consecutive number. If the whole array is consecutive then return null2. The array will always have at leas.. 2022. 8. 25.
Alternate capitalization Given a string, capitalize the letters that occupy even indexes and odd indexes separately, and return as shown below. Index 0 will be considered even. For example, capitalize("abcdef") = ['AbCdEf', 'aBcDeF']. See test cases for more examples. The input will be a lowercase string with no spaces. Good luck! Solution: def capitalize(s): return [''.join(v.lower() if i%2==1 else v.upper() for i, v i.. 2022. 8. 23.
Deodorant Evaporator This program tests the life of an evaporator containing a gas. We know the content of the evaporator (content in ml), the percentage of foam or gas lost every day (evap_per_day) and the threshold (threshold) in percentage beyond which the evaporator is no longer useful. All numbers are strictly positive. The program reports the nth day (as an integer) on which the evaporator will be out of use. .. 2022. 8. 22.
Sum of Minimums! Given a 2D ( nested ) list ( array, vector, .. ) of size m * n, your task is to find the sum of the minimum values in each row. For Example: [ [ 1, 2, 3, 4, 5 ] # minimum value of row is 1 , [ 5, 6, 7, 8, 9 ] # minimum value of row is 5 , [ 20, 21, 34, 56, 100 ] # minimum value of row is 20 ] So the function should return 26 because the sum of the minimums is 1 + 5 + 20 = 26. Note: You will alwa.. 2022. 8. 21.
Click _ argument, option으로 인자 전달하기 Click 이란? click은 커맨드 명령 환경에서 Python 스크립트에 인자를 넣을 수 있도록 도와주는 라이브러리이다. 예를 들어 하나의 스크립트가 날짜에 따라 동작이 달라져야 한다고 가정해보자. 우리는 이를 위해 날짜별로 스크립트를 만들어야 할까? 만약 그렇게 하면 매일 '오늘의 스크립트'를 새로 만들어야 할 것이다. click은 이러한 문제를 쉽게 해결해준다. 스크립트에 날짜를 인자로 넣어 하나의 스크립트만으로 모든 날짜에 대한 동작을 수행할 수 있도록 도와주기 때문이다. 이번 글에서는 간단한 예시로 click 사용법을 익혀보자. Click 사용법 1. 설치하기 pip install click 터미널에서 명령어로 click 패키지를 설치한다. 2. click 라이브러리 가져오기 # practice.. 2022. 8. 21.