Python: Check if Variable is a Dictionary

Introduction Variables act as a container to store data. A developer can use type hints when creating variables or passing arguments, however, that’s an optional feature in Python, and many codebases, old and new, are yet to have them. It’s more common for a variable in Python to have no information of the type being stored. If we had code that needed a dictionary but lacked type hints, how can we avoid errors if the variable used is not a […]

Read more

Python: How to Add Key to a Dictionary

Introduction A dictionary in Python is a collection of items that store data as key-value pairs. We can access and manipulate dictionary items based on their key. Dictionaries are mutable and allow us to add new items to them. The quickest way to add a single item to a dictionary is by using referencing a dictionary’s index with a new key and assigning a value. For example, we add a new key-value pair like this: snacks[‘chocolate’] = 5 Python allows […]

Read more

Python: How to Remove a Key from a Dictionary

Introduction In this article, we’ll take a look at how to remove keys from Python dictionaries. This can be done with the pop() function, the del keyword, and with dict comprehensions. Remove a Key Using pop(key,d) The pop(key, d) function removes a key from a dictionary and returns its value. It takes two arguments, the key is removed and the optional value to return if the key isn’t found. Here’s an example of popping an element with only the required […]

Read more

How to Merge Two Dictionaries in Python

Introduction It’s not uncommon to have two dictionaries in Python which you’d like to combine. In this article, we will take a look at various ways on how to merge two dictionaries in Python. Some solutions are not available to all Python versions, so we will examine ways to merge for selected releases too. When merging dictionaries, we have to consider what will happen when the two dictionaries have the same keys. Let’s first define what should happen when we […]

Read more

Python with Pandas: DataFrame Tutorial with Examples

Introduction Pandas is an open-source Python library for data analysis. It is designed for efficient and intuitive handling and processing of structured data. The two main data structures in Pandas are Series and DataFrame. Series are essentially one-dimensional labeled arrays of any type of data, while DataFrames are two-dimensional, with potentially heterogenous data types, labeled arrays of any type of data. Heterogenous means that not all “rows” need to be of equal size. In this article we will go through […]

Read more

Stacks and Queues in Python

Introduction Data structures organize storage in computers so that we can efficiently access and change data. Stacks and Queues are some of the earliest data structures defined in computer science. Simple to learn and easy to implement, their uses are common and you’ll most likely find yourself incorporating them in your software for various tasks. It’s common for Stacks and Queues to be implemented with an Array or Linked List. We’ll be relying on the List data structure to accommodate […]

Read more

Linked Lists in Detail with Python Examples: Single Linked Lists

Linked lists are one of the most commonly used data structures in any programming language. In this article, we will study linked lists in detail. We will see what are the different types of linked lists, how to traverse a linked list, how to insert and remove elements from a linked list, what are the different techniques to sort a linked list, how to reverse a linked list and so on. After reading this article, you should be able to […]

Read more

Python Performance Optimization

Introduction Resources are never sufficient to meet growing needs in most industries, and now especially in technology as it carves its way deeper into our lives. Technology makes life easier and more convenient and it is able to evolve and become better over time. This increased reliance on technology has come at the expense of the computing resources available. As a result, more powerful computers are being developed and the optimization of code has never been more crucial. Application performance […]

Read more

Sorting and Merging Single Linked List

In the last article, we started our discussion about the linked list. We saw what the linked list is along with its advantages and disadvantages. We also studied some of the most commonly used linked list method such as traversal, insertion, deletion, searching, and counting an element. Finally, we saw how to reverse a linked list. In this article, we will continue from where we left in the last article and will see how to sort a linked list using […]

Read more

Doubly Linked List with Python Examples

This is the third article in the series of articles on implementing linked list with Python. In Part 1 and Part 2 of the series we studied single linked list in detail. In this article, we will start our discussion about doubly linked list, which is actually an extension of single linked list. In single linked list each node of the list has two components, the actual value of the node and the reference to the next node in the […]

Read more
1 2