Skip to content

Instantly share code, notes, and snippets.

@Scimonster
Forked from kach/Symbolator
Last active December 30, 2015 17:49
Show Gist options
  • Save Scimonster/7863245 to your computer and use it in GitHub Desktop.
Save Scimonster/7863245 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
# try: cat /usr/share/dict/words | python symbols.py -
symbols = [['ac', 'actinium'], ['ag', 'silver'], ['al', 'aluminum'], ['am', 'americium'], ['ar', 'argon'], ['as', 'arsenic'], ['at', 'astatine'], ['au', 'gold'], ['b', 'boron'], ['ba', 'barium'], ['be', 'beryllium'], ['bh', 'bohrium'], ['bi', 'bismuth'], ['bk', 'berkelium'], ['br', 'bromine'], ['c', 'carbon'], ['ca', 'calcium'], ['cd', 'cadmium'], ['ce', 'cerium'], ['cf', 'californium'], ['cl', 'chlorine'], ['cm', 'curium'], ['cn', 'copernicium'], ['co', 'cobalt'], ['cr', 'chromium'], ['cs', 'cesium'], ['cu', 'copper'], ['db', 'dubnium'], ['ds', 'darmstadtium'], ['dy', 'dysprosium'], ['er', 'erbium'], ['es', 'einsteinium'], ['eu', 'europium'], ['f', 'fluorine'], ['fe', 'iron'], ['fl', 'flerovium'], ['fm', 'fermium'], ['fr', 'francium'], ['ga', 'gallium'], ['gd', 'gadolinium'], ['ge', 'germanium'], ['h', 'hydrogen'], ['he', 'helium'], ['hf', 'hafnium'], ['hg', 'mercury'], ['ho', 'holmium'], ['hs', 'hassium'], ['i', 'iodine'], ['in', 'indium'], ['ir', 'iridium'], ['k', 'potassium'], ['kr', 'krypton'], ['la', 'lanthanum'], ['li', 'lithium'], ['lr', 'lawrencium'], ['lu', 'lutetium'], ['lv', 'livermorium'], ['md', 'mendelevium'], ['mg', 'magnesium'], ['mn', 'manganese'], ['mo', 'molybdenum'], ['mt', 'meitnerium'], ['n', 'nitrogen'], ['na', 'sodium'], ['nb', 'niobium'], ['nd', 'neodymium'], ['ne', 'neon'], ['ni', 'nickel'], ['no', 'nobelium'], ['np', 'neptunium'], ['o', 'oxygen'], ['os', 'osmium'], ['p', 'phosphorus'], ['pa', 'protactinium'], ['pb', 'lead'], ['pd', 'palladium'], ['pm', 'promethium'], ['po', 'polonium'], ['pr', 'praseodymium'], ['pt', 'platinum'], ['pu', 'plutonium'], ['ra', 'radium'], ['rb', 'rubidium'], ['re', 'rhenium'], ['rf', 'rutherfordium'], ['rg', 'roentgenium'], ['rh', 'rhodium'], ['rn', 'radon'], ['ru', 'ruthenium'], ['s', 'sulfur'], ['sb', 'antimony'], ['sc', 'scandium'], ['se', 'selenium'], ['sg', 'seaborgium'], ['si', 'silicon'], ['sm', 'samarium'], ['sn', 'tin'], ['sr', 'strontium'], ['ta', 'tantalum'], ['tb', 'terbium'], ['tc', 'technetium'], ['te', 'tellurium'], ['th', 'thorium'], ['ti', 'titanium'], ['tl', 'thallium'], ['tm', 'thulium'], ['u', 'uranium'], ['uun', 'ununnilium'], ['uuo', 'ununoctium'], ['uup', 'ununpentium'], ['uus', 'ununseptium'], ['uut', 'ununtrium'], ['uuu', 'ununumium'], ['v', 'vanadium'], ['w', 'tungsten'], ['xe', 'xenon'], ['y', 'yttrium'], ['yb', 'ytterbium'], ['zn', 'zinc'], ['zr', 'zirconium']]
def complete(s):
if len(s) == 0:
yield ""
else:
for i in symbols:
if s[:len(i[0])] == i[0]:
for k in complete(s[len(i[0]):]):
yield i[1]+"-"+k
def reverse(s):
s = s.split('-')
if len(s) == 1:
return ""
else:
res = ""
for i in s:
for j in symbols:
if j[1] == i:
res += j[0]
return res
if len(sys.argv) > 1 and sys.argv[1] == "-":
for line in sorted(sys.stdin.readlines(), key=lambda x:-len(x)):
for i in complete(line[:-1]):
print line, i[:-1]
print
else:
print "Type a word to symbolate it; type symbols prefaced with \"< \" to reverse"
while True:
inp = raw_input("> ")
if inp[0] == "<":
inp = inp[2:]
print reverse(inp)
else:
for i in complete(inp):
print i
@tjvr
Copy link

tjvr commented Dec 9, 2013

You do realise Python has a reversed() function, right? :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment