Server Side Programming Articles

Page 41 of 2109

Python - Records with Key\'s value greater than K

Pranavnath
Pranavnath
Updated on 27-Mar-2026 258 Views

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 More

Printing a list vertically in Python

Pranavnath
Pranavnath
Updated on 27-Mar-2026 6K+ Views

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 More

Python – Average String length in list

Pranavnath
Pranavnath
Updated on 27-Mar-2026 826 Views

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 More

Alternate Cycling in Python List

Yaswanth Varma
Yaswanth Varma
Updated on 27-Mar-2026 518 Views

Lists in Python are ordered collections that store and manipulate a sequence of elements. Alternate cycling is the process of accessing or iterating through list elements by skipping elements in a fixed pattern, typically every second element. What is Alternate Cycling? Alternate cycling allows you to extract elements at regular intervals from a list. Here's a simple example ? Input: [1, 2, 3, 4, 5, 6] Output: [1, 3, 5] Explanation: Starting from index 0, we take every second element. Using List Slicing Slicing is the most efficient way to perform alternate cycling ...

Read More

Python Program to implement Jumbled word game

Pranavnath
Pranavnath
Updated on 27-Mar-2026 1K+ Views

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 More

Python - Records Union

Pranavnath
Pranavnath
Updated on 27-Mar-2026 268 Views

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 More

Python Program to count duplicates in a list of tuples

Pranavnath
Pranavnath
Updated on 27-Mar-2026 682 Views

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 More

Python – Print number of leap years from given list of years

Pranavnath
Pranavnath
Updated on 27-Mar-2026 474 Views

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

Python - Remove all occurrences in nested list

Pranavnath
Pranavnath
Updated on 27-Mar-2026 488 Views

When working with nested lists in Python, there are situations where we need to remove all occurrences of a specific element. Whether it's filtering unwanted data or simplifying complex structures, removing elements from nested lists is a common task. In this article, we'll explore different approaches to achieve this goal using recursion and list manipulation techniques. Advantages of Removing All Occurrences in Nested Lists Simplicity and Readability − Python provides clean and intuitive syntax, making it easier to write and understand code. Removing all occurrences in a nested list using Python is straightforward, thanks to its simplicity and ...

Read More

How to check for whitespaces in a Python Lists?

Pranavnath
Pranavnath
Updated on 27-Mar-2026 1K+ Views

Python lists can contain strings with various types of whitespace characters like spaces, tabs, or newlines. This article explores three different approaches to detect whitespace in list elements: using regular expressions, string manipulation, and the isspace() method. Using Regular Expressions The re module provides pattern matching to detect any whitespace character using \s+ regex pattern ? import re # List with various whitespace types my_list = ['hello', 'world ', ' ', '\t', 'python'] pattern = re.compile(r'\s+') for val in my_list: if pattern.search(val): ...

Read More
Showing 401–410 of 21,090 articles
« Prev 1 39 40 41 42 43 2109 Next »
Advertisements