Q:

Two If Statements with a Logical Operator

I have the following code:
fhand=open('mbox-short.txt')
count=0
for line in fhand:
    words=line.split()
    print(words)
    if len(words)==0: continue
    if words[0]!='From': continue
    print(words[2])

This code prints a valid output (I am trying to get the day of a sent email from a mbox.txt file). When I try to combine the two "if" statements as follows:
if words[0]!='From' and len(words)==0: continue

I get this error:
['From', 'stephen.marquard@uct.ac.za', 'Sat', 'Jan', '5', '09:14:16', '2008']
Sat
['Return-Path:', '<postmaster@collab.sakaiproject.org>']
Traceback (most recent call last):
  File "untitled.py", line 7, in <module>
    print(words[2])
IndexError: list index out of range

I see that the issue occurs at the Return-Path line but why is it taken into consideration? And shouldn't the combined if statement have the same output as the two separated if statements?

A:

The issue you're having is that you flipped the order of your tests. You're now testing the length after attempting to check what the first value is:
if words[0]!='From' and len(words)==0: continue

Python checks conditions from left to right, so it will first check if words[0]!='From' and then test len(words)==0, however if words is empty then the first test tries to access a non existent index and creates your error. 
You need to use this order instead and use the or operator as deceze pointed out, because you only care if one of these is True, not both.
if len(words)==0 or words[0]!='From': continue

