I don't think the code of this article shows what this principle is about. I think you are changing your code but not extending it.
Let me share what I would do with your sample. My starting point will be the first code and the adaptation to this principle will be to pass a method as an argument that do anything with the array of words.
defcount_ocurrences(counter,localfile):content=returnopen(localfile,"r").read()returncounter(content.split())defcount_and_word():'''this is the counter method to pass to the previous function'''defcount_or_word():'''another counter method'''
This sample extends the functionality of the first function without modifying it. Same method, and different ways of counting words.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I don't think the code of this article shows what this principle is about. I think you are changing your code but not extending it.
Let me share what I would do with your sample. My starting point will be the first code and the adaptation to this principle will be to pass a method as an argument that do anything with the array of words.
This sample extends the functionality of the first function without modifying it. Same method, and different ways of counting words.