You check the length:
len(x) >= 4
or you will catch an IndexError exception:
try: value = x[3] except IndexError: value = None # no 4th index
What you use depends on how often you can expect that there will be a fourth value. If this is usually the case, use an exception handler (it is better to ask for forgiveness); if you basically don't have a 4th value, check the length (look before you jump).
Martijn Pieters Mar 21 '13 at 17:31 2013-03-21 17:31
source share