Programming Articles

Page 101 of 2547

Python - Get the object with the max attribute value in a list of objects

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 4K+ Views

In Python, we can get the object with a max attribute value in a list of objects using the max() function with a lambda function, using the operator module, or using a custom comparison function. In this article, we will explore different methods to find objects with the maximum attribute value. Algorithm To get the object with the maximum attribute value in a list of objects, you can follow this common algorithm: Initialize a variable, let's call it max_object, to None initially. Iterate over each object in the list. ...

Read More

Python - Get the indices of all occurrences of an element in a list

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 12K+ Views

To retrieve the indices of all occurrences of a specific element in a list, Python provides several efficient methods. In this article, we'll explore four different approaches: using a for loop, list comprehension, the enumerate() function, and the index() method with a while loop. Using for loop The most straightforward approach is to iterate through the list using indices and compare each element with the target value. Syntax for i in range(len(data)): if data[i] == element: indices.append(i) Example def ...

Read More

Python - Get sum of last K list items using slice

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 831 Views

In Python, the slice method allows us to extract specific elements from a sequence, such as strings, lists, or tuples. It provides a concise and flexible way to work with subsequences within a larger sequence. In this article, we will explore how to obtain the sum of the last K items in a list using slice operations. Algorithm To find the sum of the last K items in a list, we can follow a simple algorithm: Accept the list and the value of K as inputs. Use the slice operator to extract the last K items ...

Read More

Python - Get particular Nested level Items from Dictionary

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 2K+ Views

Dictionaries in Python allow you to store key-value pairs, making it easy to organize and access data efficiently. Sometimes, we may need to retrieve specific items from nested levels within a dictionary. We can use recursion, isinstance() with recursion, and dict.get() methods to extract nested-level items from dictionaries. In this article, we will explore different ways to get particular nested-level items from Dictionary in Python. Nested Dictionary A nested dictionary is a dictionary that contains other dictionaries as values. This allows for the creation of hierarchical structures, where data is organized in a tree-like fashion. Each level of ...

Read More

Hyperlink-Induced Topic Search (HITS) Algorithm using Networxx Module - Python

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 4K+ Views

The Hyperlink-Induced Topic Search (HITS) algorithm is a popular algorithm used for web link analysis, particularly in search engine ranking and information retrieval. HITS identifies authoritative web pages by analyzing the links between them. In this article, we will explore how to implement the HITS algorithm using the NetworkX module in Python. Understanding HITS Algorithm The HITS algorithm is based on the idea that authoritative web pages are often linked to by other authoritative pages. It works by assigning two scores to each web page ? Authority Score: Measures the quality and relevance of information provided ...

Read More

How to Utilize Time Series in Pandas?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 301 Views

Time series data represents observations recorded over time intervals and is crucial for analyzing trends, patterns, and temporal relationships. Pandas provides comprehensive functionality for working with time series data, from basic manipulation to advanced analysis and visualization. Creating Sample Time Series Data Let's start by creating sample time series data to demonstrate the concepts − import pandas as pd import numpy as np from datetime import datetime, timedelta # Create sample time series data dates = pd.date_range('2023-01-01', periods=100, freq='D') values = np.random.randn(100).cumsum() + 100 data = pd.DataFrame({ 'value': values }, ...

Read More

How to Sort a Dictionary by Kth Index Value in Python?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 373 Views

In Python, we can sort a dictionary by the value of a specific index (kth index value) using various approaches like the sorted() function with lambda, itemgetter() from the operator module, or custom functions. Let's explore these methods with practical examples. Method 1: Using sorted() with Lambda Function This method uses the sorted() function with a lambda function to specify the sorting criterion based on the kth index value. Syntax sorted_dict = dict(sorted(dictionary.items(), key=lambda x: x[1][k])) Example Here we sort a dictionary by the second element (index 1) of each list value ...

Read More

How to search the max value of an attribute in an array object ?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 2K+ Views

When working with objects in Python, we often need to find the maximum value of an attribute in a list of objects. Python provides several approaches including simple loops, the max() function with a key parameter, and list comprehensions. In this article, we will explore these methods with practical examples. Method 1: Using For Loops In this method, we iterate through the list of objects using a loop and compare the attribute value of each object with the current maximum value. Syntax for obj in objects: if obj.attribute > max_value: ...

Read More

How to search for a string in text files using Python?

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 9K+ Views

Searching for a string in text files is an important task while doing data analysis on text data. In Python, we can search for a string in text files using various methods like reading and searching line by line, reading the entire file, and using regular expressions, or using the grep command. Method 1: Reading and Searching Line by Line One straightforward approach is to read the text file line by line and search for the desired string in each line. This method is memory-efficient and suitable for large text files. Syntax for line in ...

Read More

How to Search a Pickle File in Python

Rohan Singh
Rohan Singh
Updated on 27-Mar-2026 948 Views

Pickle is a Python module that is used for serializing and deserializing Python objects. It allows you to save and load complex data structures, such as lists, dictionaries, and even custom objects, in a binary format. When working with pickle files, you might encounter scenarios where you need to search for specific information within a pickle file. In this article, we'll explore various methods to search a pickle file in Python. Understanding Pickle Files A pickle file is a binary file that contains serialized Python objects. The pickle module in Python provides functions to convert objects into a ...

Read More
Showing 1001–1010 of 25,466 articles
« Prev 1 99 100 101 102 103 2547 Next »
Advertisements