Episode 7: Python: The Slow, Bulky But Formidable Predator

CS50 Week 6: Python

DID YOU KNOW? A python's prey dies from suffocation or cardiac arrest. When a python coils around its prey it doesn't kill it by crushing its bones. It tightens the coil every time the prey exhales effectively suffocating it. The snake can apparently detect the prey's heartbeat and waits for the beating to stop as its cue to unhinge its jaws and begin the long swallowing process.

No, Python Programming Language doesn't suffocate you the programmer. That's just an interesting fact about pythons, but if we were to force the analogy, the prey would be any stubborn tasks at hand that could easily be swallowed whole using python code.

Yes, just like python snakes, Python code is slower to execute because it has an extra step of being compiled to byte code first before it is then interpreted and executed. For most applications, this difference in speed isn't that appreciable anyway.

Python Programming Language

According to the TIOBE Index, Python is currently the most popular programming language in the world, and with good reason too! I know that many of my readers are tech-curious, so if you're looking for a place to begin your tech journey, Python is a good place to start.

On this article I'll tell you what I love most about python and mention some of the fields in which it is most applicable to help you decide if it's the language for you.

What I Love Most About Python

  • One of the least wordy languages. I gave a quick comparison with 2 code snippets of how to print "Hello World!" in Python vs C in Episode 2. Check that out here. This gives it a high level of readability because code is more often read than it is written.
  • Easy to learn. Many complexities have been abstracted away making it easy for beginners to pick up the main concepts quickly.
  • A tonne of free resources online for learning the language (all languages anyway). You could try Mosh Hamedani or Codemy or Freecodecamp for starters.
  • Many libraries. A library is like a collection of code that someone has already written to do specific tasks. E.g. If you're making a web-app and you'd like users to login, you can use a library that has all the functions for logging in and user authentication so that you don't have to write everything from scratch. (Its bulky like a python in a good way)
  • A wide Global and Kenyan community .There's actually a Python KE 2022 conference happening in Nairobi today and tomorrow (6th & 7th May) at USIU which brings together developers, startups, schools, other organisations and individuals with an interest in Python.
  • Applicable in many different fields of tech. That's actually the top reason I chose to start with Python. I'd ask my tech friends which is the best language to learn and they'd tell me that it depends on which field of tech I was hoping to get into. All I wanted was to get into tech; I didn't have any inclinations at the time so I chose to go with a language that presented the most options to choose from. Let's talk about that: the options Python gives you.

What You Can Do With Python

  • Backend Web Development. The back end is the behind-the-scenes of a website or a web application which you don't see. Like when you sign up to use a certain service, your details need to be stored on a database. The back end handles the logic necessary to make that happen. Python has many libraries and powerful frameworks like Django which make it one of the most popular languages for Backend Web Development.
  • Data Science. Python is widely used for cleaning data, data visualizations, data models etc. Again, some amazing libraries like NumPy and Pandas make this possible.
  • Machine Learning and Artificial Intelligence (ML/AI). This is where you train a program to solve a problem or make accurate predictions. Python Scikit-learn library provides many algorithms for ML.
  • Web Scrapping. You can think of this as scouring through websites to extract the data or content you need which can be very useful for research, marketing, business development etc. Beautiful Soup and Requests libraries are available for this.
  • Many others such as Game Development, Desktop Applications, Audio/Video Applications, CAD Applications etc.

There's a lot you can do with python, but before you start your coding journey I'd advise that you talk to a techie friend to help you decide.

DNA Problem Set

With a dozen examples, CS50 Week 6's lecture shows you just how easy python is in comparison to C. The problem set, however, challenges you by introducing CSV files. You need to load a csv file and read into the computer's memory the STR (Short Tandem Repeats) counts of a list of individuals. The program should then open a text file with a DNA sequence and read its content into memory as well. By computing the longest runs of STR repeats in the DNA sequence, the program should be able to cross-reference the csv file and check if there is a match in the DNA then print out the person's name. Pretty complicated but they help you by defining some functions for you.

(# An STR is a short sequence of DNA bases that tends to repeat consecutively numerous times at specific locations inside of a person’s DNA. The number of times any particular STR repeats varies a lot among individuals. This is the method used in forensic investigations for DNA profiling)

I hope you see now that Python really is a slow, bulky but formidable predator!

Up next: SQL