Find word by given characters
Bischoop
Bischoop at vimart.net
Sun Nov 1 08:38:22 EST 2020
On 2020-11-01, Bischoop <Bischoop at vimart.net> wrote:
> I'm working on a script i which user inputs letters and then a printed
> words containing those letters. The scripts works however I can't solve
> one problem , it prints also words in which these letters occur more
> than once.
> -------------------
> Fore example:
> Letters: at
> Output: auto, autobahn.
> -------------------
>
> I supposed to not print word: "autobahn" because I've given it only one
> letter "a".
>
Problem's solved.
------------
for word in words:
if all(word.count(x) == letters.count(x) for x in letters):
print(word)
-------------
Thanks for suggestions, I didn't had to use counter but going to look
into as it seems useful and interesting.
Thank You
More information about the Python-list
mailing list