Code
Diff
  • def myMap(mine):
        return [i+1 for i in mine]    
  • 11
    def myMap(mine):
    
    2
        l = [i+1 for i in mine]
    
    3
        return l
    
    4
        
    
    2+
        return [i+1 for i in mine]    
    
Code
Diff
  • from itertools import *
    
    def groups_combinations(arr2D):
        res = list(product(*arr2D))
        return [len(res), res]
        
    
  • 11
    from itertools import *
    
    2
    def product_(arr2D):
    
    3
        return product(*arr2D)
    
    44
    55
    def groups_combinations(arr2D):
    
    6
        res = []
    
    7
        for comb in product_(arr2D):
    
    8
            res.append(comb)
    
    4+
        res = list(product(*arr2D))
    
    99
        return [len(res), res]
    
    1010
        
    
Code
Diff
  • from math import sqrt, pow
    
    # calculate the distance between two points in 2d,3d ... nD
    def distanceND(pA, pB, nD = None):
        return sqrt(sum(pow(a-b,2) for a,b in zip(pA,pB)))
    
    distance2D = distanceND
        
    distance3D =distanceND
    
    
  • 11
    from math import sqrt, pow
    
    22
    33
    # calculate the distance between two points in 2d,3d ... nD
    
    44
    def distanceND(pA, pB, nD = None):
    
    55
        return sqrt(sum(pow(a-b,2) for a,b in zip(pA,pB)))
    
    66
    7
    def distance2D(pA, pB):
    
    8
        return(distanceND(pA, pB))
    
    7+
    distance2D = distanceND
    
    99
        
    
    10
    def distance3D(pA, pB):
    
    11
        return(distanceND(pA, pB))
    
    9+
    distance3D =distanceND
    
    1212
Code
Diff
  • def id_matrix(size):
         return [[i == j for j in range(size)] for i in range(size)]
    
  • 11
    def id_matrix(size):
    
    2
        return [[1 if i == j else 0 for j in range(size)] for i in range(size)]
    
    2+
         return [[i == j for j in range(size)] for i in range(size)]
    
Code
Diff
  • def  getVillianName(birthday):
        return '{} {}'.format(  FIRSTNAME[birthday.strftime("%B")], 
                                LASTNAME[birthday.strftime("%d")[1]])
    
  • 1
    22
    def  getVillianName(birthday):
    
    3
        result = ""
    
    4
    5
        result = FIRSTNAME[birthday.strftime("%B")] + " "
    
    6
        result += LASTNAME[birthday.strftime("%d")[1]]
    
    7
        return result
    
    2+
        return '{} {}'.format(  FIRSTNAME[birthday.strftime("%B")], 
    
    3+
                                LASTNAME[birthday.strftime("%d")[1]])
    
Code
Diff
  • import itertools
    
    
    def eratosthenes():
        # From Coobook recipies
        # Credits to: Credit: David Eppstein, Tim Peters, Alex Martelli,
        # Wim Stolker, Kazuo Moriwaka, Hallvard Furuseth, Pierre Denis,
        # Tobias Klausmann, David Lees, Raymond Hettinger
        D = {}
        yield 2
        for q in itertools.islice(itertools.count(3), 0, None, 2):
            p = D.pop(q, None)
            if p is None:
                D[q * q] = q
                yield q
            else:
                x = p + q
                while x in D or not (x & 1):
                    x += p
                D[x] = p
    
    
    def count_primes(limit):
        count = 0
        for prime in eratosthenes():
            if prime > limit:
                return count
            count += 1
  • 11
    import itertools
    
    2
    from itertools import *
    
    2+
    3+
    33
    def eratosthenes():
    
    4
        #From Coobook recipies
    
    5
        #Credits to: Credit: David Eppstein, Tim Peters, Alex Martelli,
    
    6
        #Wim Stolker, Kazuo Moriwaka, Hallvard Furuseth, Pierre Denis, 
    
    7
        #Tobias Klausmann, David Lees, Raymond Hettinger
    
    8
        D = {  }
    
    5+
        # From Coobook recipies
    
    6+
        # Credits to: Credit: David Eppstein, Tim Peters, Alex Martelli,
    
    7+
        # Wim Stolker, Kazuo Moriwaka, Hallvard Furuseth, Pierre Denis,
    
    8+
        # Tobias Klausmann, David Lees, Raymond Hettinger
    
    9+
        D = {}
    
    99
        yield 2
    
    1010
        for q in itertools.islice(itertools.count(3), 0, None, 2):
    
    1111
            p = D.pop(q, None)
    
    1212
            if p is None:
    
    13
                D[q*q] = q
    
    14+
                D[q * q] = q
    
    1414
                yield q
    
    1515
            else:
    
    1616
                x = p + q
    
    17
                while x in D or not (x&1):
    
    18+
                while x in D or not (x & 1):
    
    1818
                    x += p
    
    1919
                D[x] = p
    
    20
                
    
    21+
    22+
    2121
    def count_primes(limit):
    
    2222
        count = 0
    
    2323
        for prime in eratosthenes():
    
    24
            if prime > limit: return count
    
    26+
            if prime > limit:
    
    27+
                return count
    
    2525
            count += 1