Articles on Trending Technologies

Technical articles with clear explanations and examples

Python program to print even numbers in a list

Harshit Sachan
Harshit Sachan
Updated on 25-Mar-2026 13K+ Views

Python lists are fundamental data structures that store collections of items. Finding even numbers in a list is a common programming task with multiple efficient approaches. A number is even if it divides by 2 with no remainder. We will explore several methods to print even numbers from a list, each with different advantages ? Using Modulo Operator The modulo operator (%) returns the remainder when dividing two numbers. For even numbers, x % 2 == 0 will be true. Example def print_evens(numbers): for num in numbers: ...

Read More

Python program to print even length words in a string

Harshit Sachan
Harshit Sachan
Updated on 25-Mar-2026 6K+ Views

In Python, you can find and print all words in a string that have even length (divisible by 2). This is useful for text processing tasks where you need to filter words based on their character count. For example, in the string "A big cube was found inside the box", the words "cube" (length 4) and "inside" (length 6) have even lengths. Basic Approach The simplest method involves splitting the string into words and checking each word's length ? def print_even_length_words(text): # Split the string into individual words ...

Read More

Python program to find the most occurring character and its count

Pavitra
Pavitra
Updated on 25-Mar-2026 604 Views

In this article, we will learn how to find the most occurring character in a string and count its occurrences using Python's Counter class. Problem Statement Given an input string, we need to find the character that appears most frequently and return both the character and its count. Approach Create a dictionary using Counter method having characters as keys and their frequencies as values. Find the maximum occurrence count and get the corresponding character. Using Counter from collections The Counter class provides an easy way to count character frequencies ? ...

Read More

Python program to find the highest 3 values in a dictionary

Pavitra
Pavitra
Updated on 25-Mar-2026 3K+ Views

In this article, we will learn how to find the highest 3 values in a dictionary using different Python approaches. Problem Statement Given a dictionary, we need to find the three highest values and display them along with their corresponding keys. Using collections.Counter The Counter class provides a most_common() method that returns the n most common elements and their counts ? from collections import Counter # Initial Dictionary my_dict = {'a': 3, 'b': 4, 'c': 6, 'd': 5, 'e': 21} counter = Counter(my_dict) # Finding 3 highest values highest = counter.most_common(3) ...

Read More

Python Program to find the sum of array

Pavitra
Pavitra
Updated on 25-Mar-2026 1K+ Views

In this article, we will learn different approaches to find the sum of all elements in an array. Python provides both manual iteration and built-in functions to accomplish this task. Problem Statement Given an array as input, we need to compute the sum of all elements in the array. We can solve this using manual iteration or Python's built-in sum() function. Method 1: Using Built-in sum() Function The simplest approach uses Python's built-in sum() function − # Using built-in sum() function arr = [1, 2, 3, 4, 5] result = sum(arr) print('Sum of the ...

Read More

Python program to find sum of absolute difference between all pairs in a list

Pavitra
Pavitra
Updated on 25-Mar-2026 519 Views

In this article, we will learn how to find the sum of absolute differences between all pairs in a list. This involves calculating |a - b| for every pair of elements and summing the results. Problem Statement Given a list of numbers, we need to find the sum of absolute differences between all unique pairs. For example, with list [1, 3, 5], we calculate |1-3| + |1-5| + |3-5| = 2 + 4 + 2 = 8. Method 1: Using Nested Loops We can use two nested loops to iterate through all pairs and calculate their ...

Read More

Python program to find largest number in a list

Pavitra
Pavitra
Updated on 25-Mar-2026 589 Views

Finding the largest number in a list is a fundamental programming task in Python. There are several efficient approaches to accomplish this, each with different advantages depending on your specific needs. Problem Statement Given a list of numbers, we need to find the largest element efficiently. We'll explore three different approaches to solve this problem. Using Built-in max() Function The most straightforward and efficient approach is using Python's built-in max() function ? numbers = [18, 65, 78, 89, 90, 45, 23] largest = max(numbers) print("Largest element is:", largest) Largest element ...

Read More

Python program to convert decimal to binary number

Pavitra
Pavitra
Updated on 25-Mar-2026 1K+ Views

Converting decimal numbers to binary is a fundamental programming task. Python provides both manual and built-in approaches to achieve this conversion. Problem Statement Given a decimal number, we need to convert it into its binary representation. Using Recursive Approach The recursive method divides the number by 2 repeatedly and prints the remainders in reverse order − Algorithm DecToBin(num): if num > 1: DecToBin(num // 2) print num % 2 Example def DecimalToBinary(num): ...

Read More

Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array

Pavitra
Pavitra
Updated on 25-Mar-2026 422 Views

In this article, we will learn how to check whether it's possible to make a number divisible by 3 using all digits from an array of integers. Problem Statement Given an array of integers, we need to determine if we can form a number using all the digits from these integers such that the resulting number would be divisible by 3. Mathematical Concept This solution is based on a fundamental property from number theory: a number is divisible by 3 if and only if the sum of its digits is divisible by 3. This means we ...

Read More

Python program to check if the given string is pangram

Pavitra
Pavitra
Updated on 25-Mar-2026 9K+ Views

In this article, we will learn how to check if a given string is a pangram using Python. A pangram is a sentence that contains every letter of the English alphabet at least once. What is a Pangram? A pangram is a sentence or series of words that uses every letter in the English alphabet collection. Famous examples include "The quick brown fox jumps over the lazy dog" and "Pack my box with five dozen liquor jugs". Method 1: Using Manual Alphabet Check We can check each letter of the alphabet to see if it exists ...

Read More
Showing 6991–7000 of 61,298 articles
« Prev 1 698 699 700 701 702 6130 Next »
Advertisements