Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://www.hackerrank.com/challenges/validating-postalcode/problem
- ____________________________________________________
- import re
- post_code = raw_input()
- pattern = re.compile(r'([0-9]).\1')
- result = []
- pos = 0
- for _ in xrange(4):
- found = pattern.search(post_code, pos=(pos or 0))
- try:
- pos = found.start() + 1
- except AttributeError:
- break
- result.append(pos)
- print bool(re.search(r'^[1-9][0-9]{5}$', post_code) and len(result) < 2)
- https://www.hackerrank.com/challenges/detect-html-tags-attributes-and-attribute-values/problem
- ____________________________________________________
- from __future__ import print_function
- from HTMLParser import HTMLParser
- class MyParserHTML(HTMLParser):
- def print_attrib(self, attribs=None):
- if attribs:
- print(*('-> %s > %s' % (attrib[0], attrib[1]) for attrib in attribs), sep = '\n')
- def handle_starttag(self, tag, attrs):
- print(tag)
- self.print_attrib(attrs)
- def handle_startendtag(self, tag, attrs):
- print(tag)
- self.print_attrib(attrs)
- if __name__ == '__main__':
- parser = MyParserHTML()
- for _ in xrange(input()):
- parser.feed(raw_input())
- parser.close()
- https://www.hackerrank.com/challenges/ginorts/problem
- ____________________________________________________
- from __future__ import print_function
- result = sorted(raw_input(),
- key = lambda x: (not x.islower(), not x.isupper(), x.isdigit() and ord(x)%2==0, ord(x)))
- print(*result, sep = '')
- https://www.hackerrank.com/challenges/python-time-delta/problem
- ____________________________________________________
- from time import *
- def time_in_sec(tstr):
- sec1 = mktime(strptime(tstr[:-6], '%a %d %b %Y %H:%M:%S'))
- pm, hour, min = tstr[-5:-4], tstr[-4:-2], tstr[-2:]
- sec2 = - int(hour) * 3600 - int(min) * 60
- return eval('sec1%ssec2' % pm)
- for _ in xrange(input()):
- print '%i' % (abs(time_in_sec(raw_input()) - time_in_sec(raw_input())))
- https://www.hackerrank.com/challenges/merge-the-tools/problem
- ____________________________________________________
- def merge_the_tools(string, k):
- shorts = len(string)/k
- blocks = [string[i*k:(i+1)*k] for i in range(shorts)]
- result = []
- for sub in blocks:
- bet = []
- for j in sub:
- if j not in bet:
- bet.append(j)
- result.append(''.join(bet))
- for res in result:
- print res
- https://www.hackerrank.com/challenges/alphabet-rangoli/problem
- ____________________________________________________
- def print_rangoli(size):
- if size == 1:
- print 'a'
- else:
- colms = (2*size-1) * 2 - 1
- row = []
- res = []
- for i in xrange(96 + size, 96, -1):
- row.append(chr(i))
- string = '-'.join(row)+'-'+'-'.join(row[-2::-1])
- print string.center(colms, '-')
- for _ in xrange(size-1):
- row.pop()
- string = '-'.join(row)+'-'+'-'.join(row[-2::-1])
- print string.center(colms, '-')
- https://www.hackerrank.com/challenges/iterables-and-iterators/problem
- ____________________________________________________
- from __future__ import division
- from itertools import *
- input()
- string = raw_input().split()
- k = input()
- combinated = [char for char in combinations(string, k)]
- included_a = [char for char in combinated if 'a' in char]
- print len(included_a)/len(combinated)
- https://www.hackerrank.com/challenges/most-commons/problem
- ____________________________________________________
- from collections import Counter
- x = Counter(raw_input())
- result = sorted(x.most_common(3), key=lambda x: (-x[1], x[0]))
- for item, value in result:
- print item, value
- https://www.hackerrank.com/challenges/xml-1-find-the-score/problem
- ____________________________________________________
- def get_attr_number(node):
- sum = len(node.attrib)
- for child in node:
- sum += get_attr_number(child)
- return sum
- https://www.hackerrank.com/challenges/matrix-script/problem
- ____________________________________________________
- import re
- N, M = map(int,raw_input().split())
- matrix = []
- for _ in xrange(N):
- matrix.append([char for char in re.sub(r'(^.{%s}$)' % (M - 1), r'\1 ', raw_input())])
- string = ''.join([matrix[j][i] for i in xrange(M) for j in xrange(N)])
- result = re.sub(r'(?<=[A-Za-z])[!@#$%& ]+(?=[A-Za-z])' ,' ', string)
- print result
Add Comment
Please, Sign In to add comment