Server Side Programming Articles

Page 894 of 2109

Prime or not in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 832 Views

Prime numbers play a central role in many applications like cryptography. So it is a necessity to check for prime numbers using Python programs in various applications. A prime number is a number which doesn't have any factors other than one and itself. Below we'll see programs that can find out if a given number is prime or not. Basic Approach We take the following approach to decide whether a number is prime or not ? Check if the number is positive or not. As only positive numbers can be prime numbers. We divide the number ...

Read More

Maximum length of consecutive 1's in a binary string in Python using Map function

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 514 Views

When working with binary strings, you may need to find the maximum length of consecutive 1's. Python provides several approaches using built-in functions like split() with map() and regular expressions. Using Split and Map The split() function divides a string by a delimiter. When we split by '0', we get segments of consecutive 1's. The map() function applies len() to each segment, and max() finds the longest one ? Example data = '11110000111110000011111010101010101011111111' def max_consecutive_ones(binary_string): return max(map(len, binary_string.split('0'))) result = max_consecutive_ones(data) print("Maximum Number of consecutive one's:", result) ...

Read More

Usage of Asterisks in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 361 Views

Python programming language uses both * and ** in different contexts. In this article, we will explore how these operators are used and their practical applications. As an Infix Operator When * is used as an infix operator, it performs mathematical multiplication on numbers. Let's see examples with integers, floats, and complex numbers ? # Integers x = 20 y = 10 z = x * y print(z) # Floats x1 = 2.5 y1 = 5.1 z1 = x1 * y1 print(z1) # Complex Numbers x2 = 4 + 5j y2 = 5 + ...

Read More

Statistical Thinking in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 467 Views

Statistical thinking is fundamental for machine learning and AI. Since Python is the language of choice for these technologies, we will explore how to write Python programs that incorporate statistical analysis. In this article, we will create graphs and charts using various Python modules to analyze data quickly and derive insights through visualization. Data Preparation We'll use a dataset containing information about various seeds. This dataset is available on Kaggle and has eight columns that we'll use to create different types of charts for comparing seed features. The program below loads the dataset and displays sample rows. ...

Read More

Predicting Customer Churn in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 701 Views

Customer churn refers to customers leaving a business. Predicting churn helps businesses identify at-risk customers and take preventive actions. This article demonstrates how to build a machine learning model to predict telecom customer churn using Python. Dataset Overview We'll use the Telecom Customer Churn dataset which contains customer information like demographics, services, and churn status. Let's load and examine the data ? import pandas as pd # Loading the Telco-Customer-Churn.csv dataset # Dataset available at: https://www.kaggle.com/blastchar/telco-customer-churn data = pd.read_csv('Telecom_customers.csv') print("Dataset shape:", data.shape) print("First few rows:") print(data.head()) The output shows the dataset structure ? ...

Read More

Fraud Detection in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 3K+ Views

Fraud detection is a critical application of machine learning where we analyze historical transaction data to predict whether a new transaction is fraudulent. In this tutorial, we'll build a fraud detection system using credit card transaction data, applying a decision tree classifier to identify suspicious transactions. Preparing the Data We start by loading and exploring our dataset to understand its structure and features. The credit card fraud dataset contains anonymized features (V1-V28) obtained through PCA transformation, along with Time, Amount, and Class columns ? import pandas as pd # Load the credit card dataset # ...

Read More

Fast XML parsing using Expat in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 2K+ Views

Python's xml.parsers.expat module provides fast XML parsing using the Expat library. It is a non-validating XML parser that creates an XML parser object and captures XML elements through various handler functions. This event-driven approach is memory-efficient and suitable for processing large XML files. How Expat Parser Works The Expat parser uses three main handler functions ? StartElementHandler − Called when an opening tag is encountered EndElementHandler − Called when a closing tag is encountered CharacterDataHandler − Called when character data between tags is found Example Here's how to parse XML data using Expat ...

Read More

Windows registry access using Python (winreg)

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 6K+ Views

Python provides excellent support for OS-level programming through its extensive module library. The winreg module allows Python programs to access and manipulate the Windows registry, which stores configuration settings and system information. The Windows registry is organized in a hierarchical structure with keys and values. Python's winreg module provides functions to connect to, read from, and write to registry keys. Basic Registry Access First, import the winreg module and establish a connection to the registry ? import winreg # Connect to the registry access_registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) # Open a specific key access_key ...

Read More

Python - Filter the negative values from given dictionary

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 608 Views

As part of data analysis, we often encounter scenarios where we need to filter out negative values from a dictionary. Python provides several approaches to accomplish this task efficiently. Below are two common methods using different programming constructs. Using Dictionary Comprehension Dictionary comprehension provides a clean and readable way to filter negative values. We iterate through each key-value pair and include only those with non-negative values ≥ Example dict_1 = {'x': 10, 'y': 20, 'z': -30, 'p': -0.5, 'q': 50} print("Given Dictionary:", dict_1) filtered_dict = {key: value for key, value in dict_1.items() if ...

Read More

Python - Filter even values from a list

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

As part of data analysis, we often need to filter values from a list meeting certain criteria. In this article, we'll see how to filter out only the even values from a list. To identify even numbers, we check if a number is divisible by 2 (remainder is zero when divided by 2). Python provides several approaches to filter even values from a list. Using for Loop This is the simplest way to iterate through each element and check for divisibility by 2 ? numbers = [33, 35, 36, 39, 40, 42] even_numbers = ...

Read More
Showing 8931–8940 of 21,090 articles
« Prev 1 892 893 894 895 896 2109 Next »
Advertisements