Articles on Trending Technologies

Technical articles with clear explanations and examples

Adding Custom Values Key in a List of Dictionaries in Python

Disha Verma
Disha Verma
Updated on 27-Mar-2026 386 Views

In this article, we will learn how to add a custom key with corresponding values to a list of dictionaries in Python. This is a common task when working with structured data. Dictionaries in Python are collections of unordered items stored in the form of key-value pairs inside curly braces ? dictionary = {"key": "value", "name": "John"} print(dictionary) {'key': 'value', 'name': 'John'} Suppose we have a list of dictionaries called dict_list and a key new_key, with its values provided in a separate list value_list. The goal is to add new_key to each ...

Read More

Adding action to CheckBox using PyQt5

Priya Sharma
Priya Sharma
Updated on 27-Mar-2026 1K+ Views

Graphical User Interface (GUI) frameworks provide developers with the tools and capabilities to create visually appealing and interactive applications. PyQt5, a Python binding for the Qt framework, offers a robust toolkit for building GUI applications with ease. Among the fundamental components offered by PyQt5 is the CheckBox, a widget that allows users to select or deselect an option. By adding actions to CheckBoxes, we can enhance the functionality and interactivity of our applications. This feature enables us to perform specific tasks or trigger events based on the state of the CheckBox. Whether it is enabling or disabling a feature, ...

Read More

Filter key from Nested item using Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 1K+ Views

Python can extract specific values from complex data structures containing nested dictionaries or lists by filtering keys from nested items. This technique is essential for data manipulation, API response processing, and configuration parsing where you need to work with specific parts of complex data structures. Key Methods The following built-in methods are commonly used for filtering nested data ? isinstance() Checks whether an object is an instance of a specific class or type ? data = {"name": "John"} print(isinstance(data, dict)) print(isinstance([1, 2, 3], list)) True True items() Returns key-value pairs ...

Read More

Python - Find Minimum Pair Sum in list

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 808 Views

The Minimum pair sum is defined by finding the smallest possible sum of two numbers taken from a given list. This concept is useful in optimization problems where you need to minimize costs, distances, or time for operations. Python provides several approaches to solve this using built-in functions like sort(), combinations(), and float(). Using Nested for Loop This approach uses nested loops to iterate through all possible pairs and track the minimum sum ? def min_pair(nums): min_sum = float('inf') min_pair = () ...

Read More

Python - Find Index Containing String in List

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 2K+ Views

When working with mixed-type lists in Python, you often need to find the indices containing strings. This is useful for text parsing, pattern matching, and extracting specific information from data structures. Here's an example scenario: my_list = [108, 'Safari', 'Skybags', 20, 60, 'Aristocrat', 78, 'Raj'] print("Original list:", my_list) Original list: [108, 'Safari', 'Skybags', 20, 60, 'Aristocrat', 78, 'Raj'] The goal is to find indices 1, 2, 5, 7 where strings are located in this mixed list. Using for loop with type() function The most straightforward approach uses a for loop ...

Read More

Find the Index of Maximum Item in a List using Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 15K+ Views

In Python, finding the index of the maximum item in a list is a common task. Python provides several built-in functions like max(), index(), and enumerate() that can be used to find the index of the maximum item in a list. For example, given the list [61, 12, 4, 5, 89, 7], the maximum value is 89 at index 4. Using index() with max() The simplest approach combines max() to find the maximum value and index() to find its position ? numbers = [61, 12, 4, 5, 89, 7] max_index = numbers.index(max(numbers)) print(f"Maximum value: {max(numbers)}") ...

Read More

How to change Tkinter Window Icon

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 17K+ Views

Tkinter is a popular GUI (Graphical User Interface) library in Python that provides a simple way to create desktop applications. You can customize the window icon using built−in functions like Tk(), PhotoImage(), and iconphoto(). Key Methods for Changing Window Icons Tk() Creates the main window of the tkinter application ? root = Tk() PhotoImage() A class that loads and displays images. The file parameter specifies the image location ? img = PhotoImage(file='image_path.png') iconphoto() Sets the window icon using a PhotoImage object. Takes two parameters: a boolean and the image variable ...

Read More

Python - Inter Matrix Grouping

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 216 Views

Inter Matrix Grouping is a technique where elements from two lists are grouped based on matching first elements. When matches are found, the first element becomes a dictionary key, and the remaining elements form grouped values. Python provides several built-in functions like setdefault(), defaultdict(), and append() to implement this efficiently. Understanding the Concept Let's understand this with an example: list1 = [[1, 2], [3, 4], [4, 5], [5, 6]] list2 = [[5, 60], [1, 22], [4, 59], [3, 14]] # Result: {1: [2, 22], 3: [4, 14], 4: [5, 59], 5: [6, 60]} ...

Read More

How to Iterate through a List without using the Increment Variable in Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 343 Views

Iteration allows you to process each element in a list without manually managing an increment variable. Python provides several built-in functions and techniques like enumerate(), map(), list comprehension, and direct iteration that eliminate the need for manual counter variables. Using Direct Iteration (Simple For Loop) The most straightforward way is to iterate directly over list elements ? fruits = ["apple", "banana", "orange", "grape"] for fruit in fruits: print(fruit) apple banana orange grape Using enumerate() Function When you need both index and value, enumerate() provides automatic ...

Read More

How to Initialize an Empty Array of given Length using Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 27-Mar-2026 16K+ Views

An empty array consists of either null values or no elements. Empty arrays are useful when you need to initialize storage before populating it with data. Python provides several methods to create empty arrays of a given length using built-in functions and libraries. Using Multiplication (*) Operator The multiplication operator repeats elements to create an array of specified length ? length = 5 arr = [None] * length print("Empty array using multiplication operator:") print(arr) print("Length:", len(arr)) Empty array using multiplication operator: [None, None, None, None, None] Length: 5 Using NumPy empty() ...

Read More
Showing 1–10 of 61,303 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements