Store contigs and genome substrings based on mismatches
For the first question try something like:

new_substrings = []
new_positions = []
new_list = []
for pos, sub in zip(positions, substrings): 
   if not pos:
       new_list.append(sub)
   else:
       new_substrings.append(sub)
       new_positions.append(pos)


this gives:

&gt;&gt;&gt; new_substrings
['TACA']
&gt;&gt;&gt; new_positions
['11, 4']
&gt;&gt;&gt; new_list
['CTAGAAAAG']


For the hamming distance you just need to iterate over the values in seq_ref and append the results of the hamming distance function in mismatches.  Based on the given code and the example above you should be able to create that block.  Below is an untested quick example to get you on track.  

mismatches = []
for seq in seq_ref.keys():
   for value in seq_ref[seq]:
       mismatches.append(HammingDistance(seq, value))


As far as the CSV and sorting is concerned I suggest that you look into pandas or numpy.  Both of those packages provided functions to help with this.