## Fix Python – Why does Python’s hash of infinity have the digits of π?

The hash of infinity in Python has digits matching pi:
>>> inf = float(‘inf’)
>>> hash(inf)
314159
>>> int(math.pi*1e5)
314159

Is that just a coincidence or is it intentional?
….

## Fix Python – Safest way to convert float to integer in python?

Python’s math module contain handy functions like floor & ceil. These functions take a floating point number and return the nearest integer below or above it. However these functions return the answer as a floating point number. For example:
import math
f=math.floor(2.3)

Now f returns:
2.0

What is the safest way to get an integer out of this flo….

## Fix Python – Is there a math nCr function in python? [duplicate]

Statistics: combinations in Python

counting combinations and permutations efficiently

Closed 2 ….

## Fix Python – Convert a number range to another range, maintaining ratio

I’m trying to convert one range of numbers to another, maintaining ratio. Maths is not my strong point.
I have an image file where point values may range from -16000.00 to 16000.00 though the typical range may be much less. What I want to do is compress these values into the integer range 0-100, where 0 is the value of the smallest point, and 100 ….

## Fix Python – Fastest way to list all primes below N

This is the best algorithm I could come up.
def get_primes(n):
numbers = set(range(n, 1, -1))
primes = []
while numbers:
p = numbers.pop()
primes.append(p)
numbers.difference_update(set(range(p*2, n+1, p)))
return primes

>>> timeit.Timer(stmt=’get_primes.get_primes(1000000)’, setup=’import get_primes’).ti….

## Fix Python – What is the standard way to add N seconds to datetime.time in Python?

Given a datetime.time value in Python, is there a standard way to add an integer number of seconds to it, so that 11:34:59 + 3 = 11:35:02, for example?
These obvious ideas don’t work:
>>> datetime.time(11, 34, 59) + 3
TypeError: unsupported operand type(s) for +: ‘datetime.time’ and ‘int’
>>> datetime.time(11, 34, 59) + datetime.timedelta(0, 3)
Ty….

## Fix Python – What is the difference between ‘/’ and ‘//’ when used for division?

Is there a benefit to using one over the other? In Python 2, they both seem to return the same results:
>>> 6/3
2
>>> 6//3
2

….

## Fix Python – How can I check for NaN values?

float(‘nan’) represents NaN (not a number). But how do I check for it?
….