Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercise: Replace Python

Write a script called replace_python.py that given a file will replace all occurrences of "Python" or "python" by Java, but will avoid replacing the word in Monty Python. It prints the resulting rows to the screen.

For example given the input:

Just a line without either of the languages.
Line with both Python and python
A line with Monty Python.
And a  line with Monty Python and Python.

Will print:

Just a line without either of the languages.
Line with both Java and java
A line with Monty Python.
And a  line with Monty Python and Java.