Python tips that applies in all fields and let me win every coding competitions I attended.

By Md. Rahat-uz-Zaman

Elevator Pitch

Before college, I knew nothing about CS. I started coding in python and discovered some very good development methods which helped me in 1 year to win all competitions I attended. These contests were on various problems, but those tricks solved them all. The methods are for ML, contests and GIS.

Description

Who am I and why I am the right person you should listen to.

I am a student from under developed country, Bangladesh at Khulna University of Engineering and Technology (KUET). I think I am the fastest person in my country who have achieved so many prizes in very little time. I have attended and won 3 international competitions in Thailand, Sri Lanka and Malaysia. Also, I have won huge amount of national project showcasing, idea contest and hackathons and am an active competitive programmer with python. As I had no guidance, I literally started from scratch by my own. So I know where people get stuck and how they make same mistakes in their daily works. I will be discussing most of these interesting problems and how I solved these with just python. Hope these will help your daily works while programing.

The tricks

There is a package for everything.

There are 200,000+ projects officially released with PyPI. During hackathons, whenever I needed a simple task to be done, first I looked for a package that can do the thing I desire. There are 3 main reasons for it:

  1. It saves you lots of time, you just import them and use them.
  2. As the packages are released and indexed in PyPI, they are well written and in most cases, better than your implementation to solve a specific problem.
  3. The packages are maintained by someone else. So in future, if the package gets better update, your project will have better support!

Below I will discussed how I searched and found some packages during coding and saved me tons of times.

  • Networkx: On CodeSamurai 2019 international Hackathon, my team had to solve a path finding problem. They have provided me a network of Dhaka city with bus, metro, etc. I first searched if there is a package for building graph and applying algorithms on it. Then I stumbled upon this package.
  • GeoPandas: On the same event, I had to read in the csv file and convert them between coordinate reference system, measure distance and many more things. GeoPandas in combination with shapely, fiona, momepy has made life in GIS a lot easier.
  • A lot of other packages I used in other project will be demonstrated in the slide.

No need to know everything in depth. Just use as black box.

In many cases, a lot of theory is required to solve some complex problems. For the above CodeSamurai example, I did not had to implement the shortest path Dijkstra algorithm myself. There is even no need to know details of how Dijkstra works. You just need to go through the documentations. Below are some simple steps which will help you do anything without knowing too much, and leaving the learning for later. I will go through them with practical examples.

  1. Search if there exists an algorithm which will solve (or help you get close to solution) your problem.
  2. Search if there is a package that implemented this algorithm. (In almost all cases, there is a package)
  3. Just get the package, and call the right functions needed!

Machine learning and Artificial Intelligence are now the most active fields. Hard thing about these fields are, they are so much dynamic that one cannot simply keep pace knowing the latest implementations. But actually, if you want to use it in only applications, you dont need to know the details or how to implement it. Most of the algorithms are already implemented in a package. Some cool packages I want to discuss how I use are:

  1. Fastai
  2. Keras
  3. XGBoost
  4. Plotly (for visualization)
  5. Lime
  6. Librosa

Your desktop automation for everything.

I use Linux everywhere in my desktop and laptop. One great thing about python is that, it can do almost anything in your OS. You can use startup or timed running of a python script and basically do anything. In Linux, it is very simple, just use these commands which I am going demonstrate some cool applications with examples:

  • Python script with watch and sleep command.
  • Python script at startup or as kernel module.
  • Make life easy and automated with Raspberry Pi’s and Python (low level programming hacks).

Same UI template with snippets in everywhere.

I needed only two things.

1. A template for desktop application (PyQt):

Using a GUI will always give you a boost from others. For showcasing your work, imagine one person is writing commands in the terminal/cmd to run or change a configuration, whereas you just sliding your mouse and pressing buttons to show what you have done. The amount of work is minimal compared to the advantages you will get.

I try everything in GUI myself. I think the best way is to use a separate branch for this GUI while debugging. Even if a variable needs some tweaking, that variable could be a checkbox, a radio button or a slider in UI.

I am going to show you how creating GUI is very simple. Draw it in qt designer to create a UI file, load it with a simple 8 line python file, and do everything in the MainWindow function and it is done.

```python import sys import qdarkstyle from PyQt5.QtWidgets import QApplication

The MainWindow file, all the logic goes there

from MainWindow import MainWindow

app = QApplication(sys.argv) main_window = MainWindow() # Also you can use your custom style app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) main_window.show() sys.exit(app.exec_()) ```

And the MainWindow class:

python class MainWindow(QMainWindow): def __init__(self): GUI_UI_LOCATION = "./UI/MainWindow.ui" # The Qt designer file. super(MainWindow, self).__init__() loadUi(GUI_UI_LOCATION, self)

That’s it. I have created this once, and used in very simple tasks to quickly automate things. I will discuss how I enhanced it in two of my projects which won international project competitions. I have solved many other problems which I would like to discuss too.

Eyetask

Traffic Rules Violation Detection

2. A website template (Django):

In most cases, a desktop GUI is not preferable and hard to implement. As just HTML is a lot easier than creating functional widgets in PyQt or Tkinter, take this way whenever it is possible. Also it can be hosted and accessed anywhere.

For example, here is my project that won $11,770 in a Student2StartUp National competition and IEEE YESIST12 2019, Thailand International competition. Here also, I will show some problems I had in this project and how I solved it onsite.

Vision-IT

Contact me

Please feel free to contact me anywhere after the session and I would really appreciate it.

Email: rahatzamancse@gmail.com

LinkedIn: https://www.linkedin.com/in/rahatzamancse/

Github(All the above discussed projects are here): https://github.com/rahatzamancse

Notes

I am certain that discussing the problems and how I solved those will be very helpful to all the attendees. I think I am proficient in python programming and have enough experience to share my knowledge. All the competitions I won are listed in my CV which are solely done in Python. I will be presenting on my own laptop using a presentation slide and visual studio code.

CV link: https://docdro.id/hNQMYfj