def expand_string(s, all_strings):
    matches = [s2 for s2 in all_strings if all(word in s2.split() for word in
        s.split())]
if matches:
    return sorted(matches, key=len, reverse=True)[0]
else:
    return s
Comparing values in a Python dict of lists