Skip to main content
1 of 2
Bera
  • 77.8k
  • 14
  • 78
  • 188

You are not showing all your code. But you could check if split list is to short, and if so then extend with empty string. Example:

a = '1st St & A blvd'
s = a.split(' & ')
print s

diff = 3-len(s)
if diff != 0:
    s.extend([' ']*diff)
    
print s

Outputs:

['1st St', 'A blvd']
['1st St', 'A blvd', ' ']

Or use try/except:

a = [1,2]
try:
    print a[2]
except IndexError: #a[2] is not possible, will give Indexerror, then dont do anything:
    pass
Bera
  • 77.8k
  • 14
  • 78
  • 188