If you paraphrase the condition as "check that the first line consists of the same letters as the 2 and 3 lines together," you can decide, for example, by sorting the letters:
def is_merge(s, part1, part2): return sorted(part1 + part2) == sorted(s)
Other solutions are possible, for example, count how many letters are in each line and compare:
from collections import Counter def is_merge(s, part1, part2): return Counter(part1) + Counter(part2) == Counter(s)
Update. If you want a comparison without taking into account the spaces, you can filter everything from the lines except for the letters before the comparison:
def is_merge(s, part1, part2): s, part1, part2 = (list(filter(str.isalpha, item)) for item in (s, part1, part2)) return sorted(part1 + part2) == sorted(s)
For the second variant it is the same (and it is not necessary to convert the iterator that returned the filter to the list):
from collections import Counter def is_merge(s, part1, part2): s, part1, part2 = (filter(str.isalpha, item) for item in (s, part1, part2)) return Counter(part1) + Counter(part2) == Counter(s)