python 2.7 iterating index error
<pre><code>import re

address1 = []
address2 = []
city = []
state = []
zipCode = []

modifiedShipping_address1 = (
    ['#### Example Rd. SE', 'City, OH\xa0#####', 'United States', ''],
    ['### Street Ct', 'Apt B', 'City, SC\xa0#####', 'United States', ''])

for i in modifiedShipping_address1:
    address1.append(i[0])
    if len(i) == 4:
        address2.append('')
        cityIndex = str(i[1]).find(',')
        city.append(i[1][:cityIndex])
        state_re = re.compile(', (.*?)\\xa0')
        state_pat = re.findall(state_re, str(i[1]).strip())
        for i in state_pat:
            state.append(i)
            zip_re = re.compile('\\xa0(.*?)')
            zip_pat = re.findall(zip_re, str(i[1]).strip())
            for i in zip_pat:
                zipCode.append(i)
    else:
        address2.append(i[1])
        cityIndex = str(i[2]).find(',')
        city.append(i[2][:cityIndex])
        state_re = re.compile(', (.*?)\\xa0')
        state_pat = re.findall(state_re, str(i[2]).strip())
        for i in state_pat:
            state.append(i)
        zip_re = re.compile('\\xa0(.*?)')
        # This line throws the exception:
        zip_pat = re.findall(zip_re, str(i[2]).strip())
        for i in zip_pat:
            zipCode.append(i)
    state = state[:]
    zipCode = zipCode[:]

    print state
    print zipCode
</code></pre>

<p>When run, the code produces this output:</p>

<pre><code>['OH']
[]
Traceback (most recent call last):
  File "iterating.py", line 37, in &lt;module&gt;
    zip_pat = re.findall(zip_re, str(i[2]).strip())
IndexError: string index out of range
</code></pre>

<p>How do I go about fixin this? Thank you. I do not understand where indexError is coming from.</p>
