Python
-
Practice>Python>Errors and Exceptions>Incorrect Regexhackerrank.com 2019. 2. 25. 04:24
hackerrank.comIncorrect RegexProblem link : https://www.hackerrank.com/challenges/incorrect-regex/problemDifficulty : Easy TipProblem ask how to validate regular expressionJust call re.compile(), it will raise exception if the given regular expression is not valid Solution import re cnt = int(input()) for _ in range(cnt): try: re.compile(input()) print(True) except: print(False)
-
Practice>Python>Math>Power - Mod Powerhackerrank.com 2019. 2. 24. 13:52
hackerrank.comPower - Mod PowerProblem link : https://www.hackerrank.com/challenges/python-power-mod-power/problem?utm_campaign=challenge-recommendation&utm_medium=email&utm_source=24-hour-campaign&h_r=next-challenge&h_v=zenDifficulty : Easy TipVery simple/easy problemJust do as problem description :) Solution a = int(input()) b = int(input()) m = int(input()) print(pow(a, b)) print(pow(a, b, m))
-
hackerrank.com Practice>Python>Math>Mod Divmodhackerrank.com 2019. 2. 24. 13:39
hackerrank.com Mod DivmodProblem link : https://www.hackerrank.com/challenges/python-mod-divmod/problem?utm_campaign=challenge-recommendation&utm_medium=email&utm_source=24-hour-campaignDifficulty : Easy Tipdivmod() return as tupletuple can be accessible like array such as r[0] r[1] Soulution a = int(input()) b = int(input()) r = divmod(a, b) print(r[0]) print(r[1]) print(r)
-
hackerrank.com Practice>Python>Itertools>Compress the String!hackerrank.com 2019. 2. 7. 21:43
Compress the String! TipThis is quite simple problem if you understand how to use groupby()Focus two variables(k and g) are iterated from groupby()As an example groupby('aaabb'), g is 'aaa', and k is 'a' Solution from itertools import groupby s = input() o = [(len(list(g)), int(k)) for k, g in groupby(s)] print(*o)