### Say hello!

Code
Diff
• ``````def myMap(mine):
return [i+1 for i in mine]    ``````
• def myMap(mine):
• l = [i+1 for i in mine]
• return l
• return [i+1 for i in mine]

### Combinations of different groups

Code
Diff
• ``````from itertools import *

def groups_combinations(arr2D):
res = list(product(*arr2D))
return [len(res), res]

``````
• from itertools import *
• def product_(arr2D):
• return product(*arr2D)
• def groups_combinations(arr2D):
• res = []
• for comb in product_(arr2D):
• res.append(comb)
• res = list(product(*arr2D))
• return [len(res), res]

### Distance Between Two Points in a Plane and in the Space.

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

``````
• 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)))
• def distance2D(pA, pB):
• return(distanceND(pA, pB))
• distance2D = distanceND
• def distance3D(pA, pB):
• return(distanceND(pA, pB))
• distance3D =distanceND

### Create an Identity Matrix with Given Size

Code
Diff
• ``````def id_matrix(size):
return [[i == j for j in range(size)] for i in range(size)]
``````
• def id_matrix(size):
• return [[1 if i == j else 0 for j in range(size)] for i in range(size)]
• 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")])
``````
• def getVillianName(birthday):
• result = ""
• result = FIRSTNAME[birthday.strftime("%B")] + " "
• result += LASTNAME[birthday.strftime("%d")]
• return result
• return '{} {}'.format( FIRSTNAME[birthday.strftime("%B")],
• LASTNAME[birthday.strftime("%d")])

### Count Prime Numbers in Python Using a Generator

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``````
• import itertools
• from itertools import *
• 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 = { }
• # 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
• D[q * q] = q
• yield q
• else:
• x = p + q
• while x in D or not (x&1):
• 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
• if prime > limit:
• return count
• count += 1