python

CheckIO: Vigenere Cipher

from string import ascii_uppercase as alpha import itertools as it def decrypt(enc_alpha, key_alpha): if alpha.index(enc_alpha) >= alpha.index(key_alpha): return alpha[alpha.index(enc_alpha) – alpha.index(key_alpha)] else: return alpha[len(alpha) + alpha.index(enc_alpha) – alpha.index(key_alpha)] def find_key(repeated): length = 1 while length <= len(repeated): check, iter_key =…

CheckIO: Weak Point

def weak_point(matrix): check = lambda x: [sum(y) for y in x] rows, cols = check(matrix), check(zip(*matrix)) return [rows.index(min(rows)), cols.index(min(cols))] if __name__ == ‘__main__’: #These “asserts” using only for self-checking and not necessary for auto-testing assert isinstance(weak_point([[1]]), (list, tuple)), “The result…

Python: calculate weeks or months

from dateutil.relativedelta import relativedelta from datetime import datetime today = datetime.today() today.strftime(‘%Y-%m-%d’) # ‘2015-06-14’ next_week = today + relativedelta(weeks=1) next_week.strftime(‘%Y-%m-%d’) # ‘2015-06-21’ next_month = today + relativedelta(months=1) next_month.strftime(‘%Y-%m-%d’) # ‘2015-07-14’ from calendar import monthrange lastday_of_month = monthrange(2015, 6)[1] lastday_of_month #…