Decrease the cost of two lists comparisons
<p>I want to minimize the cost of comparisons of two lists that have some words. In the code below <code>A</code> has 4 words whereas <code>B</code> has 2 words and the cost is <code>O(n^2)</code> that is too bad. While for 100 words it can be time consuming. Can I minimize it somehow?</p>

<pre><code>A= ["helry", "john" , "kat" , "david"]
d="Helry David"
B = d.lower().split()

for x in range(len(A)):
            for i in range(len(B)):
                if A[x] == B[i]:
                    print("Match = " + A[x])
                else:
                    print("No")
</code></pre>

<ol>
<li>Sort array for O(nlogn) first.</li>
<li>Compare it in O(n), because you can safely assume the relationship between certain elements are the same after sorting.</li>
</ol>

python time-complexity