Skip to content

Instantly share code, notes, and snippets.

@bwbaugh
Last active December 17, 2015 05:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwbaugh/5558461 to your computer and use it in GitHub Desktop.
Save bwbaugh/5558461 to your computer and use it in GitHub Desktop.
Generating possible Twitter usernames of a certain length (in this case, 3). For @_milesokeefe
lower = [chr(x) for x in range(ord('a'), ord('z') + 1)]
# >>> lower
# ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
# 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
digits = [str(x) for x in range(10)]
# >>> digits
# ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
characters = lower + digits + ['_']
# >>> characters
# ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
# 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1',
# '2', '3', '4', '5', '6', '7', '8', '9', '_']
# >>> len(characters)
# 37
import itertools
for username in itertools.product(characters, repeat=3):
print ''.join(username)
# aaa
# aab
# aac
# aad
# aae
# aaf
# aag
# aah
# aai
# aaj
# aak
# aal
# aam
# ...
# >>> sum(1 for x in itertools.product(characters, repeat=3))
# 50653
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment