Created
August 5, 2013 10:58
-
-
Save rca/6155093 to your computer and use it in GitHub Desktop.
Find an available name on Twitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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