import itertools element_symbols = [] element_names = [] # opens files containing element symbols and names and puts them into strings for line in open('element_symbols.txt'): line = line.replace('\n', '') element_symbols.append(line) for line in open('element_names.txt'): line = line.replace('\n', '') element_names.append(line) # end symbols = [] for element in element_symbols: element = element.replace('\n', '') symbols.append(element.lower()) theinput = input('please insert phrase here: ') phrase = theinput.lower() phrase = phrase.lstrip() # separates parts of word: each group of two, for example phrase[1,2] and phrase[2,3] bits = [] counter = 0 section = '' section2 = '' for letter in phrase: section = section + letter if len(section) == 2: bits.append(section) section = '' if counter != 0: section2 = section2 + letter if len(section2) == 2: bits.append(section2) section2 = '' counter += 1 if counter == len(phrase): bits.append(letter) # end part = 0 new = [] for section in bits: for element in symbols: if element == section[0]: new.append(element) elif element == section: new.append(element) if len(new) == 0: exit() part += 1 print(new) length = range(0, len(phrase) * 2) options = {} count = 1 total = [] for each in length: print(each) for x in itertools.permutations(new, each): total.append(x) y = ''.join(x) print(y) options[y] = x count += 1 print(options) print(count) print(len(total)) #for x in itertools.permutations(new, 3): # y = ''.join(x) # options[y] = x #print(options) #complete = [] #for option in options: # if option == phrase: # complete.append(options[option]) #print(complete) #for item in complete: # item = str(item) # item = item.replace('(', '') # item = item.replace(')', '') # item = item.replace("'", '') # item_symbols = item.split(', ') # print(item_symbols) ### possibly take first 2 letters of word and see if any elements are contained ### this could be done for each group of two, for example phrase[1,2] and phrase[2,3] ### all places where case matched can be stored and placed together to create all possible versions # yay
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question