본문 바로가기

Python130

f-string f-string(formated string literal) https://www.python.org/dev/peps/pep-0498/#:~:text=These%20include%20%25%2Dformatting%20%5B1,%5B2%5D%2C%20and%20string.&text=It%20should%20be%20noted%20that,which%20contains%20expressions%20inside%20braces. PEP 498 -- Literal String Interpolation The official home of the Python Programming Language www.python.org index = 1 example = "hello" print(f'{index+1}:{exa.. 2020. 8. 12.
Enumerate Enumerate 함수는 순서가 있는 자료형 (list, set, tuple..) 을 index를 포함한 값으로 리턴한다. a = [5,4,3,2,1] list(enumerate(a)) ---> [(0,5), (1,4), (2,3), (3,2), (4,1)] 인덱스 값을 가지고 있는 값에 자동으로 순차적 부여. 2020. 8. 12.
Type Hint 타입 힌트 (Type Hint) PEP 484 에 있는 문서에 내용이 포함되어 있으며, 파이썬 함수의 파라미터와 리턴값의 type 을 쉽게 볼수 있는 가독성을 살려준다. https://www.python.org/dev/peps/pep-0484/ PEP 484 -- Type Hints The official home of the Python Programming Language www.python.org Example) #function foo takes 'a' paramter as integer and return boolean value def foo(a: int) -> bool: ... 2020. 8. 11.
LeetCode 628. Maximum Product of Three Numbers Problem: Given an integer array, find three numbers whose product is maximum and output the maximum product. Example 1: Input: [1,2,3] Output: 6 Example 2: Input: [1,2,3,4] Output: 24 Note: The length of the given array will be in range [3,104] and all elements are in the range [-1000, 1000]. Multiplication of any three numbers in the input won't exceed the range of 32-bit signed integer. -Summa.. 2020. 7. 9.
Leetcode. Squares of a Sorted Array Problem: Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order. Example 1: Input: [-4,-1,0,3,10] Output: [0,1,9,16,100] Example 2: Input: [-7,-3,2,3,11] Output: [4,9,9,49,121] -Summary- Squares of each element in Array, then sort them using sort() function. class Solution: def sortedSquares(self, A: List[in.. 2020. 7. 4.
Leetcode. Find Numbers with Even Number of Digits Problem: Given an array nums of integers, return how many of them contain an even number of digits. -Summary- 1. Format change int to string for each number and count the length of the str format of the number. 2. Check if it is even or odd number of digits. class Solution: def findNumbers(self, nums: List[int]) -> int: count = 0 for num in nums: if len(str(num)) % 2 == 0: count += 1 return coun.. 2020. 7. 1.