Revision d9f29f40-27e0-4de9-9eb1-4a03e0938a9d - Code Golf Stack Exchange
# Python (<strike>337</strike> 336 chars)
import re
i=input().split()
a,d,o,e=[],{},"",len(i)-1
for b in i:a.append(dict(re.findall(r"([A-Z][a-z]*)(\d*)",b)))
a=[{b:int(c[b])if c[b]else 1for b in c}for c in a]
for b in a:
for c in b:d[c]=c in d and d[c]+b[c]or b[c]
if"H"not in b:d["-"]=0
d["H"]-=2*e;d["O"]-=e
for b in d:o+=b+(str(d[b])if d[b]-1else"")if d[b]else""
print(o)
Here is an example of how to use this program:
sh3.14$ python dehydrate.py <-Run the program
C6H12O6 HgHO4 <-Input
O9H11C6Hg <-Output
[Try it!](https://repl.it/Bx5D/0)