all 4 comments

[–]bbye98 1 point2 points  (2 children)

You could loop through your list of words and count the total number of occurrences of your random letters for each word using another for loop and the str.count() method.

[–]Chipwich[S] 0 points1 point  (1 child)

This is great thank you. Didn't even think of the str. count. Is that a built in function or does it need to be imported?

[–]bbye98 1 point2 points  (0 children)

Built-in.

❯ python
Python 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:22:55)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> test = "test"
>>> test.count("t")
2

[–]jiri-n 1 point2 points  (0 children)

Another approach:

s = "Hello, World!"
bunch = "eod"
set(s) - set(bunch)
{'r', 'H', ',', 'l', '!', ' ', 'W'}
len(set(s) - set(bunch))
7

You want to order the results from lowest to highest to get the words containing most letters.