I’m pretty sure I’m over thinking this and there’s a simple outcome for it, but I just can’t seem to put it all together.
I’m looking for a kind of a search method. I’d like a Python script search a text file for a keyword and count how many lines it appears on. Though if the keyword comes up on a single line multiple times, I’d like to still only count it once.
Long story short; If a keyboard comes up on a single line, I want it to count that line and add it to what will be a math equation.
Any help is greatly appreciated! Thanks in advance.
You can define the following function.
Now if you want to know the number of lines containing “int” in “foo.cpp”, you do:
An alternative that you can do on the command line (if you are on an appropriate platform) is: