Python is a multi-paradigm programming language. It supports different programming paradigms like procedural programming, object-oriented programming and functional programming. In this article we will understand the basic concepts of functional programming.
Functional programming is a programming paradigm, a style to organize our code. Separation of data and functions is the main idea of functional programming. Where data is to be acted upon and functions will act or determine what to do.
In functional programming, we write the code in pure mathematical function style.
We often exchange data through text files between our programs. Maybe we need to load data from a database. Maybe we need to generate a large amount of data in our program and save them. CSV is one of the most common and popular file format to exchange data between programs.
Python has built-in
csv module to work with CSV files. This module provides us functions to work with CSV files easily.
The word CSV stands for “comma-separated values”. A CSV file is a simplified spreadsheet stored as plaintext. The structure of a CSV file is as straightforward as its…
os module in Python allows us to interact with the operating system. We can do operations like navigating the file system, creating or deleting files, finding file information, renaming files and many more using the
os module. In this article I will talk about some important things we can do with the
os module in Python.
os module comes built in with Python. So we don’t need to install it. We can simply import it in our Python file to use it.
>>> import os
We can print all the properties and methods of
Dynamic programming is a commonly studied concept in Computer Science. It is not an algorithm. Rather it is an algorithmic technique to solve optimization and counting problems. Dynamic programming was introduced by American mathematician Richard Bellman. The name “dynamic” has nothing to do with the actual process.
There is nothing dynamic in dynamic programming!
It is just a name Richard Bellman gave. So no need to get confused by the name.
To get started with the concept of dynamic programming an ideal example can be solving the Fibonacci number sequence. As it is very easy to understand. …
When we are dealing with iterables, we may need to keep track of the count of iterations. Python has a built-in function called
enumerate() to help us with that. The
enumerate() function adds counter to an iterable object and returns it as an enumerate object. Lists, tuples, strings etc. are iterable objects in Python. You can read my article on iterables and iterators. But now let’s talk about
enumerate() method takes two parameters:
enumerate()starts counting from. By default 0…
The understanding of iterables and iterators in Python is very important. But it can be a little bit tricky. In this article I will try to give a comprehensive explanation of iterables and iterators. We will understand what they are, how they work and how to use them properly.
An iterable is an object which we can iterate over and an iterator is an object which we use to iterate over an iterable!
Let’s break down this confusing definition one by one…
What does the phrase “iterate over” means? Simply it means looping over something. When we have a collection…
Python generators help us to create our own iterators. They help us to generate a sequence of values over time. If we have a large amount of values to generate, using generators is the way to go.
“Generator functions allow you to declare a function that behaves like an iterator, i.e. it can be used in a for loop “— Python Wiki
In simple words, a generator is a function that will return a iterator object. We can iterate over this object once at a time.
Implementing an iterator from scratch requires a lot of work. We have to implement…
Virtual environment in Python is a very useful concept. It helps us to manage our project dependencies properly and efficiently. In this article we will see how to create a virtual environment for our Python projects. Also how to create a
Virtual environments helps us to separate dependencies between different projects. A Python project may have a bunch of dependencies installed. And most of the time they differ from other projects’ dependencies. We don’t want to mix them up. Also dependencies get updated all the time. A project made with a previous version of a dependency may not work…
Decorators in Python allow us to add more functionalities in a function. It is called metaprogramming because one part of the program adds something to another part of the program at compile time. Decorators are used before a function with @ sign.
A decorator is a design pattern in Python that allows a user to add new functionality to an existing object without modifying its structure. Decorators are usually called before the definition of a function you want to decorate. — Datacamp’s definition of a decorator.
Following is the basic structure to use a decorator:
In this article we will build a Sorting Algorithm Visualizer using Python and Tkinter. Tkinter is a standard GUI library for Python. We will use it to create the user interface of our project. We will visualize Bubble Sort and Merge Sort. But we can implement all the comparison based sorting algorithms in this project. Wikipedia page on comparison sort.
We will structure our project files at the very beginning. First we will create a folder and name it
Sorting_Visualizer. This will be our project directory. Inside this folder we will create another folder named
algorithms. Then we will create…
Undergraduate CS student | Passionate about programming and tech