Skip to content

Instantly share code, notes, and snippets.

@rca
Created August 5, 2013 10:58
Show Gist options
  • Save rca/6155093 to your computer and use it in GitHub Desktop.
Save rca/6155093 to your computer and use it in GitHub Desktop.
Find an available name on Twitter
#!/usr/bin/env python
"""
Find a name in Twitter's packed namespace
Type in a word like your name and get some variations.
"""
import os
import sys
def cycle(word, prepend=''):
words = set([prepend+word])
if len(word) == 1:
return words
for idx, char in enumerate(word):
_word = word[idx:] + word[:idx]
words.update(cycle(_word[1:], prepend=prepend+_word[0]))
return words
if __name__ == '__main__':
try:
name = sys.argv[1]
except IndexError:
SCRIPT_NAME = os.path.basename(sys.argv[0])
sys.exit('{} <name>'.format(SCRIPT_NAME))
print '\n'.join(cycle(name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment