"Housing houses did housing," "Is it a problem that housing houses did housing?" and "That house is a harmful house.""
We have to count the number of houses There are 9 in total
i = 0
Str = "Household houses did houses," "Household houses did houses, is there a problem?" "That house is a harmful house.""
for a in Str:
If "housing" in a:
i = i + 1
print(i)
Doing it like this
I counted the number of elements in the house, so only three came out.
Is there a way to count the number of specific characters?
python list
There's nothing difficult, but if there's a quick way to get there, you can use it.
You don't have to make a wheel
But if you don't use join or count, but if you want to, I don't think you should use str.find or regular expressions. In other words, it is judged to study data structure or algorithms.
The join can be repeated and +, so it's a simple part... Count is a little bit of a big topic called search algorithm.
https://en.wikipedia.org/wiki/String-searching_algorithm
https://github.com/m00dy/string-matching-algorithms
Please refer to it and learn.
Take it easy.
It's simple if you combine the strings and process them once.
Str = "Housing houses did housing," "Is it a problem that housing houses did housing?" and "That house is a harmful house.""
paragraph = ''.join(Str)
print(paragram.count('housing'))
© 2024 OneMinuteCode. All rights reserved.