# Comparing text corpora sentence-wise in Python

I have two corpora (in the form of list of sentences); one is the "original" one, the other is a version of it with some minor changes (with contractions expaned, for instance):

s1 = ['He's a real stupid', 'There's no need to worry', 'All right, my friends']
s2 = ['He is a real stupid', 'There is no need to worry', 'All right, my friends']


I'd like to get some rendering of the corresponding sentence pairs where IS some difference between the sentences. Is there any elegant solution to this?

• If you want to compare semantic similarity (with more significant differences than your examples), look up "document embeddings", doc2vec, and paragraph2vec. – Emre Mar 20 '17 at 16:50

## 1 Answer

There are several ways to do this, but, assuming the lists are the same length and the sentences you wish to compare are in the same indices int their respective lists, you can handle this with a simple list comprehension:

diffs = [(s1[i], s2[i]) for i in range(len(s1)) if s1[i] != s2[i]]