Skip to Content

Piyush is a data professional passionate about using data to understand things better and make informed decisions. He has experience working as a Data Scientist in the consulting domain and holds an engineering degree from IIT Roorkee. His hobbies include watching cricket, reading, and working on side projects.

Merge Two Lists in Python Without Duplicates

In this tutorial, we will look at how to merge (or combine) two lists in Python such that the resulting list does not contain any duplicate elements. For example, let’s say you have the following two lists – ls1 = [1, 2, 2, 3]ls2 = [3, 4, 4, 5]after combining them the resulting list should …

Read More about Merge Two Lists in Python Without Duplicates

Merge Two Lists Alternatively in Python

In this tutorial, we will look at how to merge two lists alternatively in Python with the help of some examples. The Problem Statement Before we proceed let’s look at what we actually mean by merging two lists alternatively. Let’s say you are given two lists, list1 and list2 and you’re asked to merge the …

Read More about Merge Two Lists Alternatively in Python

Replace Single Quotes with Double Quotes in a Python String

In this tutorial, we will look at how to replace single quotes in a Python string with double quotes with the help of some examples. Replace ‘ with ” inside a string Let’s see an example to better understand the task at hand. Let’s say you have the string, “This is a ‘safe’ place”. After …

Read More about Replace Single Quotes with Double Quotes in a Python String

Swap the Case of a Python String with the swapcase() method

In this tutorial, we will look at how to swap the case of a Python string with the help of some examples. What does it mean to swap the case of a string? Swapping the case in a string refers to changing lowercase letters in the string to uppercase and uppercase letters in the string …

Read More about Swap the Case of a Python String with the swapcase() method

Swap Adjacent Characters in a Python String with this Method

In this tutorial, we will look at how we can swap adjacent characters in a string. Let’s look at an example to better understand the task at hand. Swapping adjacent characters example Let’s say you have the string, “heat”, after swapping the adjacent characters, the string becomes “ehta”. Here, we’re swapping the ith character in …

Read More about Swap Adjacent Characters in a Python String with this Method

Easily Swap Keys and Values in a Python Dictionary with this method

In this tutorial, we will look at how to swap the keys and values of a Python dictionary with the help of some examples. If you prefer a video tutorial over text, check out the following video detailing the steps in this tutorial – How to swap keys and values? Use dictionary comprehension to reverse …

Read More about Easily Swap Keys and Values in a Python Dictionary with this method

Swap Two Words in a String with these Methods in Python

In this tutorial, we will look at how to swap two words in a string in Python with the help of some examples. If you prefer a video tutorial over text, check out the following video detailing the steps in this tutorial. How is swapping words different from replacing words in a String? Note that …

Read More about Swap Two Words in a String with these Methods in Python

Swap Characters in a Python String with this Method

In this tutorial, we will look at how to swap two characters in a Python string with the help of some examples. Can you change characters in a Python string in place? No. Strings in Python are immutable so you cannot modify a string after it has been created, you can, however, create a new …

Read More about Swap Characters in a Python String with this Method