Find scrambled words within word list I'm just getting started with Python -- completing a simple exercise from a practice website.  My code works -- just looking for feedback on better ways to achieve the goal.

Goal:


  Find the original (unscrambled) words, which were randomly taken from
  a wordlist. Send a comma separated list of the original words, in the
  same order as in the list below.


I stored the scrambled words in words.txt and the wordlist in wordlist.txt

#!/usr/bin/env python3

# open word files
wordlist = open("wordlist.txt", "r").read().split()
words = open("words.txt", "r").read().split() 

s = list()

# loop through scrambled words
for word in words:
    # break scrambled word into characters
    chars = list(word)
    # loop through comparison list
    for compare in wordlist:
        # break compare word into characters
        compare_chars = list(compare)
        # make copy of scrambled characters
        char_list = chars[:]
        # loop through scrambled word characters
        for char in chars:
            # if character not in compare word go to next compare word
            if not char in compare_chars:
                break
            # if character found remove it (in case character exists more than once)
            compare_chars.remove(char)
            char_list.remove(char)
        # if all compare characters exhausted we *may* have found the word
        if not compare_chars:
            # if all scrambled characters are utilized then we have the right word
            if not char_list:
                s.append(compare)
            else:
                s.append('???')
            break

# create comma separated list of words
print(",".join(s))
I'm not a Python programmer but I would take this approach, as if I understand the problem correctly, it seems like an easy solution. Along side that I believe it makes us of the language features also.

#!/usr/bin/env python3

# open word files
wordlist = open("wordlist.txt", "r").read().split()
words = open("words.txt", "r").read().split() 

s = list()

# loop through scrambled words
for word in words:
    # break scrambled word into characters
    chars = sorted(list(word))
    # loop through comparison list
    for compare in wordlist:
        if sorted(list(compare)) == chars:
            s.append(compare)

# create comma separated list of words
print(",".join(s))


This works on the bases that we do not care for order, so an ordered list of each will be a good check.

I have not broken out of the inner loop, as it is unclear weather multiple words could match and all of those words should be returned or not.

This is untested, as stated, I'm not a Python programmer.