Hackerrank - Validating Postal Codes Solution A valid postal code have to fullfil both below requirements: must be a number in the range from to inclusive. must not contain more than one alternating repetitive digit pair.
Hackerrank - Maximize It! Solution You are given a function . You are also given lists. The list consists of elements. You have to pick one element from each list so that the value from the equation below is maximized:
Hackerrank - Triangle Quest 2 Solution You are given a positive integer N. Your task is to print a palindromic triangle of size N. For example, a palindromic triangle of size 5 is: 1 121 12321 1234321 123454321 You can't take more than two lines. The first line (a for-statement) is already written for
Validating Email Addresses With a Filter Solution You are given an integer followed by email addresses. Your task is to print a list containing only valid email addresses in lexicographical order. Valid email addresses must follow these rules: * It must have the [email protected] format type. * The username can only contain letters, digits, dashes and underscores.
Hackerrank - Time Delta Solution When users post an update on social media,such as a URL, image, status update etc., other users in their network are able to view this new post on their news feed. Users can also see exactly when the post was published, i.e, how many hours, minutes or seconds ago.
Hackerrank - Set .add() solution If we want to add a single element to an existing set, we can use the .add() operation. It adds the element to the set and returns 'None'. Example >>> s = set('HackerRank') >>> s.add('H') >>>
Python Re.start() & Re.end() start() & end() These expressions return the indices of the start and end of the substring matched by the group.
Python Re.findall() & Re.finditer() re.findall() The expression re.findall() returns all the non-overlapping matches of patterns in a string as a list of strings. Code >>> import re >>> re.findall(r'\w','http://www.hackerrank.com/') ['h', 't', 't&
Python Group(), Groups() & Groupdict() group() A group() expression returns one or more subgroups of the match. Code >>> import re >>> m = re.match(r'(\w+)@(\w+)\.(\w+)','[email protected]') >>> m.group(0) # The entire match '[email protected]' >
Hackerrank - Power - Mod Power Solution So far, we have only heard of Python's powers. Now, we will witness them! Powers or exponents in Python can be calculated using the built-in power function. Call the power function as shown below: >>> pow(a,b) or >>> a**b It'