Fix reference to keys()[0] -- doesn't work in py3
Use assertEquals(set, set) instead of fancier test functions.
Fix substitution: don't use sets.

This patch makes string substitution behave consistently. List variables are
substituted in the order.