Python Container Types: A Quick Guide

If you’re working with Python, most of the data structures you’ll think about are container types. πŸš‚πŸšƒπŸšƒπŸšƒ These containers are special data structures that hold and manage collections of elements. Python’s most commonly used built-in container types include tuples, lists, dictionaries, sets, and frozensets πŸ“¦. These containers make it easy for you to store, manage … Read more

Dictionary of Lists to DataFrame – Python Conversion

Problem Formulation Working with Python often involves processing complex data structures such as dictionaries and lists. In many instances, it becomes necessary to convert a dictionary of lists into a more convenient and structured format like a Pandas DataFrame 🐼. DataFrames offer numerous benefits, including easier data handling and analysis πŸ”, as well as an … Read more

Python | Split String Key Value

Summary: There are three different ways to split the given string into keys and values: Minimal Example Problem Formulation Problem: Given a string containing key-value pairs. How will you split the string to get the key-value pairs? Example You have to split the string given in the problem below using the delimiter “:” in such … Read more

Python Create JSON File

Problem Formulation and Solution Overview This article focuses on working with a JSON file. JSON is an acronym for JavaScript Object Notation. This is a flat-text file formatted based on JavaScript (JS) Syntax. This file is most commonly noted for its ability to transmit data to/from web applications, such as sending/receiving data from a Server/Client … Read more

How to Count the Number of Unique Values in a List in Python?

Problem Statement:Β Consider that you have been given a list in Python. How will you count the number of unique values in the list? Example: Let’s visualize the problem with the help of an example: Given:Β li = [‘a’, ‘a’, ‘b’, ‘c’, ‘b’, ‘d’, ‘d’, ‘a’]Output:Β The unique values in the given list are ‘a’, ‘b’, ‘c’, ‘d’. … Read more

Python TypeError: ‘dict_values’ Not Subscriptable (Fix This Stupid Bug)

Do you encounter the following error message? TypeError: ‘dict_values’ object is not subscriptable You’re not alone! This short tutorial will show you why this error occurs, how to fix it, and how to never make the same mistake again. So, let’s get started! Solution Python raises the “TypeError: ‘dict_values’ object is not subscriptable” if you … Read more

Python TypeError: ‘dict_keys’ Not Subscriptable (Fix This Stupid Bug)

Do you encounter the following error message? TypeError: ‘dict_keys’ object is not subscriptable You’re not alone! This short tutorial will show you why this error occurs, how to fix it, and how to never make the same mistake again. So, let’s get started! Solution Python raises the “TypeError: ‘dict_keys’ object is not subscriptable” if you … Read more

Python Print Dictionary Keys Without “dict_keys”

Problem Formulation and Solution Overview If you print dictionary keys using print(dict.keys()), Python returns a dict_keys object, i.e., a view of the dictionary keys. The representation prints the keys enclosed in a weird dict_keys(…) wrapper text, e.g., dict_keys([1, 2, 3]). Here’s an example: There are multiple ways to change the string representation of the keys, … Read more