Server Side Programming Articles

Page 52 of 2109

Python - Filter Tuples with All Even Elements

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

Filtering tuples with all even elements is a common operation in Python data processing. This involves checking if every element in each tuple is divisible by 2 and keeping only those tuples that satisfy this condition. Using List Comprehension with all() The most Pythonic approach combines list comprehension with the all() function to filter tuples where every element is even ? tuple_list = [(6, 4, 2, 8), (5, 6, 7, 6), (8, 0, 2), (7, ), (2, 4, 6)] result = [tup for tup in tuple_list if all(ele % 2 == 0 for ele in ...

Read More

Check if a Word is Present in a Sentence

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

In Python, checking if a word is present in a sentence is a common task in text processing and string manipulation. Python provides multiple approaches including the in operator, find() method, and split() method for word-by-word matching. Using the in Operator The simplest way to check if a word exists in a sentence is using Python's in operator ? sentence = "The bestseller book is amazing" word = "book" if word in sentence: print("The given word is present in the sentence.") else: print("The given word is not ...

Read More

Check if a number with even number of digits is palindrome or not

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

A palindrome is a number that reads the same forwards and backwards. This article shows how to check if a number with an even number of digits is a palindrome in Python. Examples include 2662, 4224, 44, 1001, etc. Using String Comparison The simplest approach converts the number to a string and compares it with its reverse ? def is_even_digit_palindrome(num): # Convert number to string num_str = str(num) # Check if even number of digits ...

Read More

Python - K List Dictionary Mesh

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

The term dictionary mesh refers to creating a nested dictionary structure where each element from the first list becomes a key, and each element from the second list becomes a nested key with empty lists as values. This creates a mesh-like structure that can hold organized data. Understanding Dictionary Mesh Given two input lists ? list1 = [10, 20, 30] list2 = [40, 50] The dictionary mesh creates this structure ? {10: {40: [], 50: []}, 20: {40: [], 50: []}, 30: {40: [], 50: []}} Method 1: Using Nested ...

Read More

Python Tensorflow - tf.keras.Conv2D() Function

Parth Shukla
Parth Shukla
Updated on 27-Mar-2026 907 Views

In deep learning, computer vision is one of the most important fields used for complex tasks like image analysis, object detection, and segmentation. TensorFlow and Keras provide powerful built-in functions that automate and simplify the model training process. The Conv2D function is one of the most useful tools in Keras for applying convolutional operations to images. In this article, we'll explore what Conv2D is, how to use it, and see practical examples. What are Convolutional Operations? Convolutional operations are fundamental operations used in Convolutional Neural Networks (CNNs) to extract features from input image data. These operations use ...

Read More

Compute Classification Report and Confusion Matrics in Python

Parth Shukla
Parth Shukla
Updated on 27-Mar-2026 1K+ Views

In machine learning, classification problems require careful evaluation to understand model performance. The classification report and confusion matrix are essential tools that help us evaluate classification models and identify where they make mistakes. This article will explore these evaluation methods through practical Python examples, covering their components, interpretation, and implementation using scikit-learn. What is a Confusion Matrix? A confusion matrix is a table that summarizes the performance of a classification model by comparing predicted vs. actual values. It contains four key components ? True Positive (TP): Model correctly predicts positive class True Negative (TN): Model ...

Read More

Python - K Elements Reversed Slice

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

K Elements Reversed Slice extracts the last K elements from a list and returns them in reverse order. This technique is useful for data analysis, queue processing, and extracting recent entries from datasets. What is K Elements Reversed Slice? A K elements reversed slice takes the last K elements from a list and reverses their order. For example, if we have [1, 2, 3, 4, 5] and K=3, we get the last 3 elements [3, 4, 5] reversed as [5, 4, 3]. Using Slicing The most concise approach uses Python's slice notation with negative indexing and ...

Read More

Python - Filter unequal elements of two lists corresponding same index

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

When working with two lists in Python, you may need to find elements that are equal at the same index positions. This is useful for data comparison, synchronization, and filtering operations. For example, given two lists: list1 = [10, 20, 30, 40, 50] list2 = [1, 20, 3, 40, 50] # Elements at same index: 20, 40, 50 are equal Using zip() and List Comprehension The most Pythonic approach uses zip() to pair elements and list comprehension to filter matches − list1 = [1, 2, 3, 4, 5] list2 = [1, 2, ...

Read More

Finding Words with both Alphabet and Numbers using Python

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

Finding words that contain both alphabetic characters and numeric digits is a common text processing task in Python. This tutorial demonstrates four different approaches using built-in functions like filter(), isdigit(), isalpha(), and regular expressions. Problem Overview Given a text string, we need to extract words that contain both letters and numbers ? Input my_text = "WELCOME TO CLUB100" print("Input:", my_text) Input: WELCOME TO CLUB100 Expected Output ['CLUB100'] Method 1: Using Regular Expressions Regular expressions provide a powerful pattern-matching approach to find words containing both letters and digits ...

Read More

Python - Find first Element by Second in Tuple List

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

Finding the first element by the second in a tuple list is a common operation in Python. Given a list of tuples where each tuple contains two elements, you need to search for a specific second element and return its corresponding first element. This is useful for key-value lookups and data filtering operations. Let's understand this with an example ? # Example tuple list countries = [("India", 35), ("Indonesia", 12), ("London", 31), ("Germany", 20)] # Search for the country with population 31 search_value = 31 # Expected output: "London" Method 1: Using a for ...

Read More
Showing 511–520 of 21,090 articles
« Prev 1 50 51 52 53 54 2109 Next »
Advertisements