This repository contains my code used for the playlist "Python tips and tricks", which is available on my Youtube channel YUNIKARN. Visit Our website for more content.
You wrote your code relying on Python packages. It runs perfectly - but after a while, you get error messages! Well, Python packages keep changing. How do you address this issue? This video introduces virtual environments (VE) and demonstrates how they can be created, activated and deactivated. Finally, we illustrate the problem based on recent changes to PyPDF2.
- 0:00 Introduction
- 0:41 Why use a VE?
- 2:10 Creating a VE
- 3:51 Activate
- 4:46 Pip installer
- 5:10 PyPDF2
This is my favourite interview question: "Write a function called sum_of_even_numbers. The function should accept a list of integers. It returns the sum of all even numbers in the list. Finally, print this number." I will discuss two ways to address this question using for loops and list comprehension.
This is a more challenging interview question: "Select a point P inside the square of length q randomly (2D). Each point P is the centre of a circle of radius r. Note that circles must be inside the square and cannot overlap. Determine the probability of drawing a point in N draws, which is the centre of a permitted circle." Complicated? This video illustrates how to tackle complex questions step-by-step.
You might have seen a requirements.txt in a GitHub repository. Why do people use it? Moving virtual environments into other folders or uploading to other machines is usually a bad idea (paths can break, security concerns etc.). This video shows you how to make a requirements.txt. Then we demonstrate how to install packages in your virtual environment using a requirements.txt.
We explore the os module, which offers many useful methods to interact with your operating system. I show you how to obtain and change your current working directory. However, it is often better to avoid using a machine-specific path.
We explore importing data from CSV files to Python. In addition, important options, including variable names and indices, are discussed. Finally, we select columns from Pandas DataFrames and briefly cover Pandas Series.
We introduce the Python package Pulp, which is used for optimisation problems. Using a simple example, we build our first model and find solutions. This is a linear programming exercise.
Pulp offers excellent tools to model optimisation problems based on finding optimal routes (e.g., delivery, transportation, supply chains). We explore a simple example where a company has the choice to outsource production, which might lower delivery costs.