The best way is to move your Q# code into a separate .qs file in the same directory as both of your notebooks. The IQ# notebook will automatically compile the .qs file and make the operations available when you load the notebook, and the Python notebook will do the same when you run import qsharp
.
You'll specify your Q# namespace inside the .qs file. Here's an example of what such a .qs file might look like.
Possibly useful tip: From inside an IQ# notebook, you can use the %who
magic command to list all available operations that you've either defined in the notebook or that have been compiled from .qs files. From Python, you can do the same by running print(qsharp.get_available_operations())
.