For some reason most people always use “Mary and I” (or “he and I” or “she and I,” etc.) in a sentence, no matter where the phrase lies. So they end up saying something like this: “Mary and I went for a walk. A cop gave Mary and I a ticket for jaywalking.”
The first sentence is correct, but the second sentence is incorrect. Why? In grammatical terms, the rule goes like this: Use “Mary and I” when the phrase is the subject of the sentence, and use “Mary and me” when the phrase is the object of a verb or preposition. But that might as well be a foreign language to some people.
It is helpful to note that “Mary and I” often comes at the beginning of a sentence, while “Mary and me” comes in the middle or at the end of a sentence. But that doesn't always work.
The best way I’ve found to determine which to use is simply to take out the “Mary and.” Then read the sentence and see what sounds better. Thus: “I went for a walk” sounds good, but “A cop gave I a ticket for jaywalking” sounds odd. It should be “A cop gave me a ticket for jaywalking.” Thus we should use, “A cop gave Mary and me a ticket for jaywalking.”
Here are some more examples:
He and I both like to eat sour apples.
It seems to her and me that we should turn left here.
On Friday, Sarah and I went to the movies.
Don’t tell Fred and me what to do.