Found 33676 Articles for Programming

Adding Custom Values Key in a List of Dictionaries in Python

Disha Verma
Updated on 14-Aug-2023 12:34:14

277 Views

In this article, we will learn how to add a custom key with corresponding values to a list of dictionaries in Python. Dictionaries in Python are collections of unordered items stored in the form of key-value pairs inside curly braces like this − Dictionary = {key: value, ….} 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 dictionary in dict_list, assigning it the corresponding value from value_list. Let’s understand it with an example − #List of dictionary we ... Read More

Adding action to CheckBox using PyQt5

Priya Sharma
Updated on 14-Aug-2023 12:32:08

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, updating ... Read More

Filter key from Nested item using Python

Tapas Kumar Ghosh
Updated on 14-Aug-2023 12:36:01

963 Views

Python can extract a specific value from a complex data structure that has nested dictionaries or lists by filtering a key from a nested item. The key is a unique identifier for a certain value inside the nested item. Based on this problem statement it has various application domains such as data manipulation, data interaction, and, API interaction. Syntax The following syntax is used in the examples- append() This is a built−in method in Python that adds the element at the end of the list. isintance() Python has a built−in function called isinstance() that determines whether an object ... Read More

Python - Find Minimum Pair Sum in list

Tapas Kumar Ghosh
Updated on 14-Aug-2023 12:34:34

666 Views

The Minimum pair sum is defined by finding the smallest possible sum of two numbers taken from a given list of numbers. It can be used to solve challenges when minimizing the total of two elements is important, such as reducing the cost, distance, or time necessary for a certain operation. In Python, we have some built−in functions like float(), sort(), combination(), and, range() will be used to find the minimum pair sum in a list. Syntax The following syntax is used in the examples- float('inf') The float() is a built−in method in Python that accepts the parameter to ... Read More

Python - Find Index Containing String in List

Tapas Kumar Ghosh
Updated on 16-Aug-2023 10:41:50

2K+ Views

Sometimes working with Python string, we may come across a real-world scenario where it can be useful for text parsing, pattern matching, and extracting specific information from text data. In Python, we have some built-in functions such as type(), index(), append(), and, isinstance() will be used to find the index containing String in List. Let’s take an example of this: The given input string, my_list = [108, 'Safari', 'Skybags', 20, 60, 'Aristocrat', 78, 'Raj'] Output 1, 2, 5, 7 Explanation The variable name my_list stores the input list that contains the mixing of integer and string in ... Read More

Find the Index of Maximum Item in a List using Python

Tapas Kumar Ghosh
Updated on 14-Aug-2023 12:29:42

14K+ Views

In Python, the index of maximum item refers to a specific index in which the item will be greater than all the elements of the list. In Python, we have some built−in functions len(), max(), series(), idxmax(), and index() that can be used to find the index of maximum item in a list. Let’s take an example of this. The given string, [61, 12, 4, 5, 89, 7] So, the maximum present index becomes 4 i.e. 89. Syntax The following syntax is used in the examples- len() The len() is a built−in method in Python that returns the object ... Read More

How to change Tkinter Window Icon

Tapas Kumar Ghosh
Updated on 14-Aug-2023 12:25:28

16K+ Views

The Tkinter is a popular GUI(Graphical User Interface) library in Python that provides a simple and easy way to create a GUI application. In Python, we have some built−in functions such as Tk(), PhotoImage(), mainloop(), title(), and, wm_title() will be used to change the Tkinter Window Icon. Syntax The following syntax is used in the examples- Tk() This built−in method in Python creates the main window of the tkinter application. PhotoImage(file='image_address_link') The PhotoImage is a class in the tkinter module that allows displaying the image with the help of a parameter named file that sets the image location. ... Read More

Python - Inter Matrix Grouping

Tapas Kumar Ghosh
Updated on 14-Aug-2023 12:22:26

148 Views

The Inter Matrix Grouping is the set of two different lists where the sublist of first element will be considered to be common matches and if the matches are found it makes the first element as key in the dictionary, and the rest two elements are set for matrix grouping. In Python, we have some built−in functions such as setdefault(), defaultdict(), and, append() will be used to solve the Inter Matrix Grouping. Let’s take an example of this. The given two lists are: list_1 = [[1, 2], [3, 4], [4, 5], [5, 6]] list_2 = [[5, 60], [1, 22], [4, ... Read More

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

Tapas Kumar Ghosh
Updated on 14-Aug-2023 12:18:22

271 Views

The iteration is a simple programming algorithm to take some steps to iterate all the elements present in a list. The main feature of iteration is to repeat the code of block multiple times. In Python, we have some built−in functions such as enumerate(), list(), map(), and, lambda will be used to iterate through a list without using the increment variable. Syntax The following syntax is used in the examples enumerate() The enumerate() is an in−built function in Python that can be used to track the specific iteration. list() The list() is a built−in method in Python that ... Read More

How to Initialize an Empty Array of given Length using Python

Tapas Kumar Ghosh
Updated on 14-Aug-2023 12:15:07

15K+ Views

An empty array consists of either a null value or no element. The empty array is very special to programming when the programmer uses the condition to perform specific tasks. In Python, we have some built−in functions such as empty(), append(), range(), and, extend() will be used to Initialize an empty array of the given length. Syntax The following syntax is used in the examples empty() The empty() is an in−built function in Python that returns the new array in the form of given length and type. append() The append() is an in−built function in Python that inserts ... Read More

Advertisements