본문 바로가기

전체 글137

LeetCode 937. Reorder Data in Log Files Problem: You have an array of logs. Each log is a space delimited string of words. For each log, the first word in each log is an alphanumeric identifier. Then, either: Each word after the identifier will consist only of lowercase letters, or; Each word after the identifier will consist only of digits. We will call these two varieties of logs letter-logs and digit-logs. It is guaranteed that eac.. 2020. 8. 17.
Regular expression operation (re.sub) re.sub(pattern, repl, string, count=0, flags=0) s = re.sub('[^a-z0-9]','',s) #[a-z0-9] --> matching any lower case letter a to z and digit of 0-9 ''' This will replace any special characters in 's' string with non-space blank characters. ''' -Example- s = 'abc#@%921' s = re.sub('[^a-z0-9]', '', s) s --> 'abc921' https://docs.python.org/3/library/re.html#re.sub re — Regular expression operations .. 2020. 8. 16.
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.