Find word by given characters

Bischoop Bischoop at vimart.net
Tue Nov 3 18:35:44 EST 2020


On 2020-11-03, duncan smith <duncan at invalid.invalid> wrote:
>> 
>
>>>> from collections import Counter
>>>> letters = 'att'
>>>> letter_counts = Counter(letters)
>>>> word = 'tolerate'
>>>> wd_counts = Counter(word)
>>>> for char, cnt in letter_counts.items():
> 	print (cnt == wd_counts[char])
>
> 	
> True
> True
>>>> word = 'auto'
>>>> wd_counts = Counter(word)
>>>> for char, cnt in letter_counts.items():
> 	print (cnt == wd_counts[char])
>
> 	
> True
> False
>>>>
>
> or, equivalent to the above loop, but breaking when the first False is
> generated and returning the single Boolean that you're after,
>
>>>> all(cnt == wd_counts[char] for char, cnt in letter_counts.items())
> False
>>>>
>
> There's still a lot of scope for improvement, but possibly not by doing
> simple things


lol

I'm thinking about it for a couple days and you guys coming with few
ideas to it like it's nothing.
Pity I've wasted a decade with woman, now probably to old to learn
anything new.



More information about the Python-list mailing list