This file contains hidden or 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 operator | |
def max_value(m): | |
return max(m.iteritems(), key=operator.itemgetter(1))[0] |
This file contains hidden or 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 fractions import gcd | |
def eulers_totient(n): | |
p = 0 | |
for k in range(1, n+1): | |
if gcd(n,k) == 1: | |
p += 1 | |
return p |
This file contains hidden or 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
def swap(s, i, j): | |
return ''.join((s[:i], s[j], s[i+1:j], s[i], s[j+1:])) |
This file contains hidden or 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 itertools | |
def remove_duplicate(s): | |
return ''.join(ch for ch, _ in itertools.groupby(s)) |
This file contains hidden or 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
def remove_spaces(s): | |
return s.replace(' ', '') |
This file contains hidden or 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
def remove_leading_zeros(s): | |
while s[0] == '0': | |
s = s[1:] | |
return s |
This file contains hidden or 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
def remove_trailing_zeros(s): | |
while s[-1] == '0': | |
s = s[:-1] | |
return s |
This file contains hidden or 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 datetime | |
def isDate(date_text, fmt): | |
try: | |
datetime.datetime.strptime(date_text, fmt) | |
except ValueError: | |
return False | |
return True |
This file contains hidden or 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
def sum_of_digits(n): | |
s = 0 | |
while n > 0: | |
s += n % 10 | |
n /= 10 | |
return s |
This file contains hidden or 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
#!/usr/bin/env python3 | |
""" Rename an AWS dynamodb table attribute with an exponential timing back-off | |
""" | |
import logging | |
from time import sleep | |
import boto3 | |
from boto3.dynamodb.conditions import Attr |