This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def fun(s): | |
return re.fullmatch(r'^[a-zA-Z0-9_\-]+[@]{1}[a-zA-Z0-9]+[.]{1}[a-zA-Z]{1,3}$', s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib = lambda n: fib(n-1)+fib(n-2) if n>1 else n | |
print(list(map(lambda x: x**3, [fib(n) for n in range(int(input().strip()))]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
for i in range(int(raw_input())): | |
try: | |
if re.compile(raw_input()): print True | |
except: | |
print False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for _ in range(int(input())): | |
try: | |
a, b = map(int, input().split()) | |
print(a//b) | |
except (ZeroDivisionError, ValueError) as e: | |
print("Error Code:", e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
for _ in range(int(input())): | |
t1=datetime.strptime(input(),'%a %d %b %Y %H:%M:%S %z') | |
t2=datetime.strptime(input(),'%a %d %b %Y %H:%M:%S %z') | |
print (int(abs((t1-t2).total_seconds()))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import calendar | |
m,d,y = map(int, input().split()) | |
print(calendar.day_name[calendar.weekday(y, m, d)].upper()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
b=int(input()) | |
a=input().split() | |
c=int(input()) | |
a=''.join(sorted(a)) | |
a_count=0 | |
for i in combinations(a,c): | |
if 'a' in i:a_count+=1 | |
print ("%0.3f" %(a_count/len(list(combinations(a,c))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import product | |
k, m = map(int, input().split()) | |
arrays = [list(map(int, input().split()[1:])) for _ in range(k)] | |
lst = [] | |
for a in list(product(*arrays)): | |
lst.append(sum([b ** 2 for b in a]) % m) | |
print(max(lst)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import groupby | |
for k,g in groupby((raw_input()), int): | |
print (len(list(g)),k), | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations_with_replacement | |
S,K = raw_input().split() | |
print "\n".join("".join(i) for i in list(combinations_with_replacement(sorted(S),int(K)))) |
NewerOlder