Difference between del remove and pop in Python

Introduction In today's Python code snippet, we are going to talk about deleting, removing and popping list elements: remove method: takes a value as input, searches for it, removes the first match. If the item is not found it errors out ValueError: list.remove(x): x not in list del function: removes an item at a specific

Flatten a list of lists in Python

Welcome to a new Python code snippet. In this post, we are going to suggest a couple of methods to flatten a list of lists. The final output is going to be a one dimensional list. Let us take an example: # Given the following list of lists # Write code to flatten it. The

Difference between mutual exclusion and synchronization

Introduction Welcome to a new operating systems post. Today, we are going to clarify some terms frequently used in concurrency and operating systems design. You have probably heard of the following terms... Processes and threads Shared memory and resources Race conditions Mutual exclusion Critical section or critical region Synchronization primitives or constructs Locks and spin

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

Difference between concurrency and parallelism

Introduction Concurrency and parallelism are often used interchangeably in computing, however they do not necessarily mean the same thing. If you Google concurrency vs parallelism, you will find different articles explain it differently. I think part of the confusion comes from the way people define these terms. In this post, I am not going to