본문 바로가기

Python345

Row Weights Scenario Several people are standing in a row divided into two teams. The first person goes into team 1, the second goes into team 2, the third goes into team 1, and so on. Task Given an array of positive integers (the weights of the people), return a new array/tuple of two integers, where the first one is the total weight of team 1, and the second one is the total weight of team 2. Notes Array .. 2022. 8. 16.
Playing with digits Some numbers have funny properties. For example: 89 --> 8¹ + 9² = 89 * 1 695 --> 6² + 9³ + 5⁴= 1390 = 695 * 2 46288 --> 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51 Given a positive integer n written as abcd... (a, b, c, d... being digits) and a positive integer p we want to find a positive integer k, if it exists, such that the sum of the digits of n taken to the successive powers of p is equal.. 2022. 8. 15.
Give me a Diamond Jamie is a programmer, and James' girlfriend. She likes diamonds, and wants a diamond string from James. Since James doesn't know how to make this happen, he needs your help. Task You need to return a string that looks like a diamond shape when printed on the screen, using asterisk (*) characters. Trailing spaces should be removed, and every line must be terminated with a newline character (\n)... 2022. 8. 14.
python-dotenv _ 환경변수를 .env 파일로 관리하기 환경변수란? 환경변수(environment variable)는 컴퓨터가 사용하는 동적인 변수를 의미한다. 여기서 동적이란 '고정적이지 않은'이라는 의미이다. 환경변수는 프로세스를 동작시키는 데 사용하는 변수를 매번 새로 입력할 필요 없이, 시스템에 설정해두어 사용하는 변수를 의미한다. 이번 글에서 Python 프로그램을 실행할 때 환경변수를 파일 단위로 관리할 수 있는 python-dotenv에 대해 알아보자. 환경변수 설정 방법 mac 기준, 환경 변수를 설정하는데 ‘임시 설정’과 ‘영구 설정’ 두 가지 방법이 있다. 임시 설정 사용자가 터미널에 직접 환경 변수를 할당한다. 터미널에 export [환경변수 이름]=[환경변수 값] 형식으로 명령어를 입력해보자. export environ=456 다시 ex.. 2022. 8. 13.
Consecutive strings You are given an array(list) strarr of strings and an integer k. Your task is to return the first longest string consisting of k consecutive strings taken in the array. Examples: strarr = ["tree", "foling", "trashy", "blue", "abcdef", "uvwxyz"], k = 2 Concatenate the consecutive strings of strarr by 2, we get: treefoling (length 10) concatenation of strarr[0] and strarr[1] folingtrashy (" 12) co.. 2022. 8. 13.
Maximum subarray sum The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers: max_sequence([-2, 1, -3, 4, -1, 2, 1, -5, 4]) # should be 6: [4, -1, 2, 1] Easy case is when the list is made up of only positive numbers and the maximum sum is the sum of the whole array. If the list is made up of only negative numbers, return 0 instead. Empty list i.. 2022. 8. 12.