Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Pranavnath
Page 4 of 39
Python - Rear stray character String split
When working with strings in Python, you may encounter situations where delimiter characters appear in unexpected places, creating "stray characters" that interfere with standard string splitting operations. This article explores three effective approaches to handle string splitting when delimiters appear after certain words or in non-standard positions. What are Stray Characters in String Splitting? Stray characters are delimiters (like periods, commas, or spaces) that appear in positions where they disrupt normal string splitting patterns. For example, a period that appears immediately after a word without a following space can cause split operations to produce unexpected results. Why ...
Read MorePython – Records list XOR
Python provides several methods to perform XOR (exclusive OR) operations on lists of records. XOR allows us to compare two lists and identify unique elements between them, returning elements that exist in either list but not in both. In this article, we'll explore three different approaches to applying XOR operations on lists with step-by-step implementations and examples. Understanding XOR Operation on Lists XOR (exclusive OR) is a logical operation that returns true when operands are different and false when they are the same. When applied to lists, XOR combines two lists and returns elements found in either list ...
Read MorePython – Rear Addition of Record
In this article, we will explore three different approaches for adding records to the end of a dataset in Python. These methods provide efficient and flexible solutions for data-processing tasks. We will cover the usage of Python lists, Python's built-in deque class, and NumPy arrays. Each approach offers its own advantages, depending on factors such as performance and ease of implementation. The rear addition of a record in Python refers to the process of adding a new data entry to the end or rear of an existing dataset. It is a common operation in data-handling tasks, where new information ...
Read MorePython - Records with Key\'s value greater than K
When working with data in Python, a common task is filtering records based on specific criteria. This article explores different approaches to filter records (dictionaries) based on a key's value being greater than a given threshold K. We'll demonstrate two efficient methods: using a loop and list comprehension. Understanding Python Records In Python, records are typically represented as dictionaries with key-value pairs. Here are the key characteristics of dictionaries ? Key-Value Pairing − Each dictionary contains key-value pairs where the key serves as an identifier for its associated value. Dictionary Syntax − Dictionaries are defined using ...
Read MorePrinting a list vertically in Python
When working with lists in Python, sometimes you need to display elements vertically instead of the default horizontal format. This article explores three different approaches to print list elements in a vertical arrangement. Basic List Structure A Python list stores elements in square brackets and normally prints horizontally ? fruits = ['apple', 'banana', 'cherry'] print(fruits) ['apple', 'banana', 'cherry'] Method 1: Using Simple For Loop The most straightforward approach uses a for loop to print each element on a separate line ? fruits = ['apple', 'banana', 'cherry'] for ...
Read MorePython – Average String length in list
Calculating the average length of strings in a list is a common task in Python. This involves finding the total length of all strings and dividing by the number of strings. Python offers several approaches including statistics.mean(), for loops, and map() functions. Using statistics.mean() Function The statistics module provides a built-in mean() function that calculates averages efficiently ? import statistics words = ["Sharpener", "book", "notepad", "pencil"] lengths = [len(word) for word in words] avg_length = statistics.mean(lengths) print("Average string length:", avg_length) Average string length: 6.5 Using For Loop A ...
Read MorePython Program to implement Jumbled word game
A Jumbled Word Game is an engaging word puzzle where players unscramble letters to form meaningful words. This brain-teasing game challenges vocabulary skills and improves problem-solving abilities. In this article, we'll implement a jumbled word game using Python with three different approaches. Approach 1: Randomizing Letters The first approach randomly shuffles the letters of a word and displays it to the player. The player must rearrange the letters to form the correct word. Algorithm Step 1 − Define a list of words for the game Step 2 − Randomly select a word from the list ...
Read MorePython - Records Union
Data manipulation and analysis are essential tasks in programming. Python provides powerful tools for handling and transforming data, including the union of records − combining multiple datasets into a single comprehensive dataset. This article explores three approaches to achieve record union in Python with practical examples. What is Records Union? Records Union refers to combining multiple datasets or records into a single comprehensive dataset. It involves merging datasets based on common attributes or creating a unified dataset containing all unique records from the original datasets. Record union is valuable for: Consolidating information from different sources Integrating ...
Read MorePython Program to count duplicates in a list of tuples
Counting duplicates in a list of tuples is a common task in data analysis and data processing. Python provides several approaches to efficiently count the occurrences of tuples in a list. In this article, we'll explore different algorithms and their implementations to count duplicates in a list of tuples using Python. Advantages of Counting Duplicates in Tuple Lists Simplicity and readability − Python's clean syntax makes counting duplicates straightforward with concise, readable code. Efficient data processing − Python provides built-in data structures and libraries optimized for efficient data processing. Tools like dictionaries, the Counter class, and Pandas ...
Read MorePython – Print number of leap years from given list of years
A leap year occurs every four years and has 366 days instead of 365. The extra day is added to February, making it 29 days. Python provides several ways to identify and count leap years from a list of years. A year is a leap year if it's divisible by 4, but if it's divisible by 100, it must also be divisible by 400 to be a leap year. Using Lambda Function with Calendar Module The calendar.isleap() function with filter() and lambda provides a concise solution − import calendar # List of years to ...
Read More