Python
-
Practice>Python>Regex and Parsing>Group(), Groups() & Groupdict()hackerrank.com 2019. 3. 29. 13:09
hackerrank.com Group(), Groups() & Groupdict() Problem Link : https://www.hackerrank.com/challenges/re-group-groups/problem Difficulty : Easy Tip a-zA-Z0-9 this to capture both alphabet and number Solution import re m = re.search(r'([a-zA-Z0-9])\1+', input().strip()) print(m.groups()[0] if m else -1)
-
Practice>Python>Regex and Parsing>Re.split()hackerrank.com 2019. 3. 29. 12:53
hackerrank.com Re.split() Problem Link : https://www.hackerrank.com/challenges/re-split/problem Difficulty : Easy Tip Regular expression is a key for handling string [,.]+ characters inside '[]' they can be repeated from 0 to mutiple times Solution regex_pattern = r"[,.]+"# Do not delete 'r'. import re print("\n".join(re.split(regex_pattern, input())))
-
Practice>Python>Numpy>Concatenatehackerrank.com 2019. 3. 28. 12:30
hackerrank.com Concatenate Problem Link : https://www.hackerrank.com/challenges/np-concatenate/problem Difficulty : Easy Tip Create input for creating numpy array like below a1 = [input().split() for _ in range(N)] so far a1 is string, need to convert it to int arr1 = numpy.array(a1, int) Concatenate arr1 and arr2 :) Solution import numpy as np N, M, P = list(map(int, input().split())) a1 = [inp..
-
Practice>Python>Built-Ins>Any or Allhackerrank.com 2019. 3. 27. 13:04
hackerrank.comAny or AllProblem Link : https://www.hackerrank.com/challenges/any-or-all/problemDifficulty : Easy Tiphow to check the number is palindromicPlease use ::-1, it make reverse arraypalindromic number means that original and reverse are samev == v[::-1] 0 for v in N1) Solution input() N2 = input().split(' ') N1 = list(map(int, N2)) r1 = all(v > 0 for v in N1) r2 = any(v == v[::-1] for ..
-
Practice>Python>Numpy>Shape and Reshapehackerrank.com 2019. 3. 26. 12:45
hackerrank.comShape and ReshapeProblem link : https://www.hackerrank.com/challenges/np-shape-reshape/problemDifficulty : Easy TipMost of thing to resolve problem, is described in descriptionJust add 'int' when you create numpy arrary, like numbpy.array(arr, int)It is to covert string to int Solution import numpy arr = input().split(' ') arr = numpy.array(arr, int) print(numpy.reshape(arr,(3,3)))
-
Practice>Python>Numpy>Arrayshackerrank.com 2019. 3. 26. 12:38
hackerrank.comArraysProblem link : https://www.hackerrank.com/challenges/np-arrays/problemDifficulty : Easy Tipdouble colon :: is keyyou guys know regarding single colon : It's time to understand the usage of ::key is [::-1] to reverse numpy array Solution import numpy def arrays(arr): return numpy.array(arr, float)[::-1] arr = input().strip().split(' ') result = arrays(arr) print(result)
-
Practice>Python>Debugging>Default Argumentshackerrank.com 2019. 3. 22. 13:03
hackerrank.comDefault ArgumentsProblem link : https://www.hackerrank.com/challenges/default-arguments/problemDifficulty : Medium TipVery interesting problem regarding default argumentI surprised that the instance of default argument, is alive alwaysNot to use same instance, we should init the instance every timeProbably, not easy to understand, please see the solution Solution class EvenStream(o..
-
Practice>Python>Python Functionals>Reduce Functionhackerrank.com 2019. 3. 22. 12:45
hackerrank.comReduce FunctionProblem link : https://www.hackerrank.com/challenges/reduce-function/problemDifficulty : Medium TipPlease read problem description carefully regarding reduce()lambda function can take multiple argumentlambda x, y: x*y, [[1,2],[3,4],[5,6]](1*2)*(3*4)*(5*6) Solution from fractions import Fraction from functools import reduce def product(fracs): t = reduce(lambda x, y: ..