Search code examples
pythonreduceexpand

Is there any way in Python to reduce/expand my code similar to the R function of "{ }"?


I have written quite a complex program in Python 3.7. However I am looking for a way to reduce (and later on expand again) my already functional functions. So that I don't have to scroll over 200 lines of code whenever I want to get back to the top.

As I said, I am writing my code in Python 3.7 and this seems like a pretty easy/beginner technique. However, I tried googling a lots of stuff, unfortunately English is not my native language and I have no idea of what to google. And googling for "reduce code in Python" ain't gonna work me. Thus I am hoping you Geeks could help me! :)

E.g.

Instead of

1 # This is some random code

2 print("Hello")

3 print("beautiful")

4 print("World")

5 # This is some random code

I want to have

1 # This is some random code

2-4 # Here all the other lines should be reduced to one line

5 # This is some random code

Solution

  • Utilize code folding in an IDE. Suggested IDES for Anaconda can be found here. I'd recommend Visual Studio Code. IDE for anaconda