Skip to content

Instantly share code, notes, and snippets.

@JordanReiter
Created December 13, 2012 16:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JordanReiter/4277424 to your computer and use it in GitHub Desktop.
Save JordanReiter/4277424 to your computer and use it in GitHub Desktop.
A logarithmic generator: 1, 2, …, 8, 9, 10, 20, 30, …, 80, 90, 100, 200, …. Especially useful those times when you want to see how a function behaves over a wide range of numbers but don't want to have to actually look at all of those numbers.
def log_gen(n):
import math
y = 1
while y < n:
adder = max(1, math.pow(10, int(math.log10(y))))
yield int(y)
y = y + adder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment