Question: I want to find out if one string is equal to at least one of the permutations of the other string.
For example, the output of the following two comparisons must be `true`:

```
print('united states of America' == 'America united states of')
print('united states of America' == 'states of united America')

```

I used the `itertools.permutations` method to find permutations, but
I want it for words not the sentence nor the letters in the string.

So not `'abcd' == 'bcad'` equals `True`, but `'a b c d' == 'b c a d'`
should be `True`.

Answer: 
The solution I would recommend is to find the frequency of each word in each string and compare that.

The actual implementation is a little bit more tricky, we first find the frequencies of each word in the first string, and then for each word in te second string we decrement the frequency by 1, if the frequency is less than 0, we know that the second string has that word more times that the first string and we can skip the rest of the words.

```py
def compare(s1, s2):
    count = {}  # this is the frequencies dict
    for word in s1.split():
        count[word] = count.get(word, 0) + 1  # increment the frequency of the word
    for word in s2.split():
        count[word] = count.get(word, 0) - 1  # decrement the frequency of the word
        if count[word] < 0:
            # s2 has more of this word than s1
            return False
    return True

```

---

This algorithm is faster than sorting or `itertools.permutations` but takes more space. The time complexity of this algorithm is `O(n)` where `n` is the number of words, compared with `O(nlog n)` for sorting, and `O(n!)` for `itertools.permutations`.
A computationally more efficient way of doing it compared to permutations would be to split and sort the strings and compare the sorted lists. A challenge with generating permutations is that as soon as you start getting just a couple of words, e.g. 10, then you would have 10! number of permutations (3628800) generated which you would compare your string against making it very inefficient very fast.

```py
string_1 = "states of united America"
string_2 = "united states of America"

def check_if_perm(s1, s2):
    return sorted(s1.split()) == sorted(s2.split())

```

outputs:

```
True

```