본문 바로가기

replace10

0210. Is it a number? Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not. Valid examples, should return true: isDigit("3") isDigit(" 3 ") isDigit("-3.23") should return false: isDigit("3-4") isDigit(" 3 5") isDigit("3 5") isDigit("zero") Solution: def isDigit(string: str) -> bool: return string.strip().lstrip("-").replace(".", "").isd.. 2023. 2. 10.
0107. Exclamation marks series #4: Remove all exclamation marks from sentence but ensure a exclamation mark at the end of string Description: Remove all exclamation marks from sentence but ensure a exclamation mark at the end of string. For a beginner kata, you can assume that the input data is always a non empty string, no need to verify it. Examples remove("Hi!") === "Hi!" remove("Hi!!!") === "Hi!" remove("!Hi") === "Hi!" remove("!Hi!") === "Hi!" remove("Hi! Hi!") === "Hi Hi!" remove("Hi") === "Hi!" Solution: const remo.. 2023. 1. 7.
1114. Exclamation marks series #6: Remove n exclamation marks in the sentence from left to right Description: Remove n exclamation marks in the sentence from left to right. n is positive integer. Examples remove("Hi!",1) === "Hi" remove("Hi!",100) === "Hi" remove("Hi!!!",1) === "Hi!!" remove("Hi!!!",100) === "Hi" remove("!Hi",1) === "Hi" remove("!Hi!",1) === "Hi!" remove("!Hi!",100) === "Hi" remove("!!!Hi !!hi!!! !hi",1) === "!!Hi !!hi!!! !hi" remove("!!!Hi !!hi!!! !hi",3) === "Hi !!hi!!! !.. 2022. 11. 14.
1105. Remove exclamation marks Write function RemoveExclamationMarks which removes all exclamation marks from a given string. Solution: class RemoveExclamationMarks: def get(self, s): return s.replace("!", "") remove_exclamation_marks = RemoveExclamationMarks().get 2022. 11. 5.
Python _ zoneinfo 사용법, ZoneInfo 와 pytz 차이 ZoneInfo 을 사용하면 기존 pytz를 사용하지 않고도 타임존을 사용할 수 있다! (*ZoneInfo 는 Python3.9 버전 이상부터 사용가능) 'ZoneInfo' vs 'pytz' 그렇다면 ZoneInfo 와 pytz 는 어떤 차이가 있을까? 우선 ZoneInfo 는 따로 설치할 필요가 없는 빌트인 클래스이므로 다음처럼 간단하게 불러올 수 있다. from zoneinfo import ZoneInfo ZoneInfo 와 pytz 를 각각 사용해 현재시간을 가져와보자. pytztz = timezone("Asia/Seoul") zonetz = ZoneInfo("Asia/Seoul") print(datetime.datetime.now(tz=pytztz).tzname()) print(datetime.d.. 2022. 10. 27.
0929. Summing a number's digits Write a function named sumDigits which takes a number as input and returns the sum of the absolute value of each of the number's decimal digits. For example: (Input --> Output) 10 --> 1 99 --> 18 -32 --> 5 Let's assume that all numbers in the input will be integer values. Solution: def get_str_number(func): def wrapper(number): return func(str(number).replace("-", "")) return wrapper @get_str_nu.. 2022. 9. 29.