Skip to content
Advertisement

How to extract words with a repeated letter not count one specific? python

I have a multiple word file where the same letters appear multiple times. I’ve already learned to catch these words.

Now I would like the words with the letter “a” not to be counted by the script.

My file.txt:

JavaScript

my code:

JavaScript

result:

JavaScript

I try to make that only “a” can repeat in a word, if “a” is repeated and another letter, this word is to be extracted

Expects to not recognize the word “abaa” as a result Because, in this word, only “a” is repeated. No other letter repeated.

If the “a” and another letter are repeated then the word is to be extracted in this case

Advertisement

Answer

If you don’t want to catch repeated a then if it out!

JavaScript

But if you don’t mind, your program could be improved.

Firstly, and string[qq] has no effect – for normal letters it always evaluates to True

Secondly, your count (unless you plan to extend the program to allow different number of counts) could be a boolean,

JavaScript

And as a bonus, you have a Counter in python which generally do what you want:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement