If you want to compare general strings, to avoid issues with unicode, I suggest you normalize the strings and use casefold:
import unicodedata
def normalize_caseless(text):
return unicodedata.normalize("NFKD", text.casefold())
old_sql = ["select * from T1", "select * from T2", "select * from T3"]
new_sql = ["SELECT * FROM T1", "SELECT * FROM T3", "SELECT * FROM T2"]
if set(map(normalize_caseless, old_sql)) == set(map(normalize_caseless, new_sql)):
print("equals")
else:
print("not equals")
Output
equals
You can see why this is useful, in this answer.
Also note that you could use a set, which makes the comparison O(n) (expected), although with larger constants. So this should be faster that O(nlogn) for larger lists.
Set will only work if there are not duplicates strings, for that case you could use collections.Counter:
import unicodedata
from collections import Counter
def normalize_caseless(text):
return unicodedata.normalize("NFKD", text.casefold())
old_sql = ["select * from T1", "select * from T2", "select * from T3"]
new_sql = ["SELECT * FROM T1", "SELECT * FROM T3", "SELECT * FROM T2"]
if Counter(map(normalize_caseless, old_sql)) == Counter(map(normalize_caseless, new_sql)):
print("equals")
else:
print("not equals")