Tag: Python

Python for loop else clause

Introduction In this post, we are going to discuss a rarely used Python feature. We are familiar with the regular for and while loops but using an else clause after a loop is not common. We can live without this language feature however it can be used to write elegant code. Let us take an

Merge sort in Python

Problem Implement merge sort algorithm in Python. Solution For definition and explanation, You may refer to the following post. This post is just a rewrite in Python. Before jumping directly to the code, check out the following nice YouTube clip Recursive merge sort in python Take a look at the comments for explanation… Thanks for

Difference between iterators and generators in Python

Table of contents Introduction What is an iterator? Iterator example What is an iterable? Iterable example – separate class Iterable example – single class Python containers What are generators? Generator types Generator function example Generator comprehension example Generator advantages Summary References Introduction Today, we are going to discuss a little bit confusing topic in Python