Python: Average distance between string elements in a list
<p>I am trying to calculate the average distance between string list elements. So the average distance between names below.</p>

<pre><code>testList = ['sarah', 'jon', 'mark', 'jessica', 'sarah', 'sarah', 'liz',
'jon', 'liz', 'sarah', 'jon', 'mark']
</code></pre>

<p>So <code>Sarah --&gt; Jon</code>: <code>[0, 2, 1, 1, 0]</code>. The average distance between them is 0.8. </p>

<p><code>Sarah --&gt; Mark</code>: <code>[1, 1, 1]</code>. The average distance between them is 1.</p>

<p>I started writing code for this, but got stuck. I am also new to Python and would like to learn how to write this code using basic Python fundamentals like loops, instead of using a library.</p>

<pre><code>def nameDistance(nameOne, NameTwo):
  distance = 0
  distanceList = []
  for name in nameList:
    if name == nameOne or nameTwo:
      #continue parsing through nameList but increment distance by 1 for each name 
      #that is not nameOne or nameTwo
      #once we get to the other name passed in the function
      #append distance to distanceList and set distance back to zero
      #continue to do this for the rest of nameList
      #take the average of distanceList 
</code></pre>