title: How to iterate over each string in a list of strings and operate on its elements?
body: <p>Given a list:</p>
  <pre class="lang-py prettyprint-override"><code>words = ['aba', 'xyz', 'xgx', 'dssd', 'sdjh']
  </code></pre>
  <p>I need to compare the first and the last element of each string in the list. If the first and the last element in the string is the same, then increment the count.</p>
  <p>If I try it manually, I can iterate over each element of the strings in the list:</p>
  <pre><code>words = ['aba', 'xyz', 'xgx', 'dssd', 'sdjh']
  w1 = words[0]
  print w1
  aba
  
  for i in w1:
     print i
   
  a
  b
  a
  
  if w1[0] == w1[len(w1) - 1]:
     c += 1
     print c
   
  1
  </code></pre>
  <p>But, when I try to iterate over all the elements of all the strings in the list , using a <code>for</code> loop, I get an error.</p>
  <pre><code>words = ['aba', 'xyz', 'xgx', 'dssd', 'sdjh']
  c = 0
  for i in words:
       w1 = words[i]
       if w1[0] == w1[len(w1) - 1]:
         c += 1
       print c
  </code></pre>
  <p>ERROR:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 2, in &lt;module&gt;
  TypeError: list indices must be integers, not str
  </code></pre>
  <p>How would I achieve comparing the first and the last element of a list of strings?</p>