def get_elements(): return { "H":["Hydrogen",1], "He":["Helium",2], "Li":["Lithium",3], "Be":["Beryllium",4], "B":["Boron",5], "C":["Carbon",6], "N":["Nitrogen",7], "O":["Oxygen",8], "F":["Fluorine",9], "Ne":["Neon",10], "Na":["Sodium",11], "Mg":["Magnesium",12], "Al":["Aluminium",13], "Si":["Silicon",14], "P":["Phosphorus",15], "S":["Sulfur",16], "Cl":["Chlorine",17], "Ar":["Argon",18], "K":["Potassium",19], "Ca":["Calcium",20], "Sc":["Scandium",21], "Ti":["Titanium",22], "V":["Vanadium",23], "Cr":["Chromium",24], "Mn":["Manganese",25], "Fe":["Iron",26], "Co":["Cobalt",27], "Ni":["Nickel",28], "Cu":["Copper",29], "Zn":["Zinc",30], "Ga":["Gallium",31], "Ge":["Germanium",32], "As":["Arsenic",33], "Se":["Selenium",34], "Br":["Bromine",35], "Kr":["Krypton",36], "Rb":["Rubidium",37], "Sr":["Strontium",38], "Y":["Yttrium",39], "Zr":["Zirconium",40], "Nb":["Niobium",41], "Mo":["Molybdenum",42], "Tc":["Technetium",43], "Ru":["Ruthenium",44], "Rh":["Rhodium",45], "Pd":["Palladium",46], "Ag":["Silver",47], "Cd":["Cadmium",48], "In":["Indium",49], "Sn":["Tin",50], "Sb":["Antimony",51], "Te":["Tellurium",52], "I":["Iodine",53], "Xe":["Xenon",54], "Cs":["Caesium",55], "Ba":["Barium",56], "La":["Lanthanum",57], "Ce":["Cerium",58], "Pr":["Praseodymium",59], "Nd":["Neodymium",60], "Pm":["Promethium",61], "Sm":["Samarium",62], "Eu":["Europium",63], "Gd":["Gadolinium",64], "Tb":["Terbium",65], "Dy":["Dysprosium",66], "Ho":["Holmium",67], "Er":["Erbium",68], "Tm":["Thulium",69], "Yb":["Ytterbium",70], "Lu":["Lutetium",71], "Hf":["Hafnium",72], "Ta":["Tantalum",73], "W":["Tungsten",74], "Re":["Rhenium",75], "Os":["Osmium",76], "Ir":["Iridium",77], "Pt":["Platinum",78], "Au":["Gold",79], "Hg":["Mercury",80], "Tl":["Thallium",81], "Pb":["Lead",82], "Bi":["Bismuth",83], "Po":["Polonium",84], "At":["Astatine",85], "Rn":["Radon",86], "Fr":["Francium",87], "Ra":["Radium",88], "Ac":["Actinium",89], "Th":["Thorium",90], "Pa":["Protactinium",91], "U":["Uranium",92], "Np":["Neptunium",93], "Pu":["Plutonium",94], "Am":["Americium",95], "Cm":["Curium",96], "Bk":["Berkelium",97], "Cf":["Californium",98], "Es":["Einsteinium",99], "Fm":["Fermium",100], "Md":["Mendelevium",101], "No":["Nobelium",102], "Lr":["Lawrencium",103], "Rf":["Rutherfordium",104], "Db":["Dubnium",105], "Sg":["Seaborgium",106], "Bh":["Bohrium",107], "Hs":["Hassium",108], "Mt":["Meitnerium",109], "Ds":["Darmstadtium",110], "Rg":["Roentgenium",111], "Uub":["Ununbium",112], "Uut":["Ununtrium",113], "Uuq":["Ununquadium",114], "Uup":["Ununpentium",115], "Uuh":["Ununhexium",116], "Uus":["Ununseptium",117], "Uuo":["Ununoctium",118], } elements_map = get_elements() elements_keys = elements_map.keys() elements = [] for abbr in elements_keys: elements.append(abbr) def check_elemental(test_string): options = [] singles = [None]*len(test_string) doubles = [None]*(len(test_string)-1) for index, char in enumerate(test_string): char = char.capitalize() singles[index] = char in elements_map if index != 0: substring = test_string[index-1:index+1].capitalize() doubles[index-1] = substring in elements_map def element_search(string,index=0,results=[]): success = False if index >= len(string): options.append("-".join(results)) success = True else: if singles[index]: next_results = list(results) item = string[index].capitalize() next_results.append(item) success = element_search(string,index+1,next_results) if index < len(string)-1 and doubles[index]: next_results = list(results) item = string[index:index+2].capitalize() next_results.append(item) success = element_search(string,index+2,next_results) return success success = element_search(test_string) print("%s: %s [%s]" % (test_string,success,",".join(options))) check_elemental("Sarah") check_elemental("Chris") check_elemental("Paff") check_elemental("Cami") check_elemental("Soren") check_elemental("Aaron") check_elemental("Austin")