Programming Articles

Page 900 of 2547

Arithmetic operations in excel file using openpyxl in Python

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

Python can help us work with Excel files directly from the Python environment using the openpyxl module. We can refer to individual cells or ranges of cells in Excel and apply arithmetic operators on them. The results of these operations can be stored in specific cells whose location we define in our Python program. In the examples below, we perform various arithmetic operations using built-in Excel functions like SUM, AVERAGE, PRODUCT, and COUNT. We use the openpyxl module to create a workbook, store values in predefined cells, apply functions on those cells, and save the results to other cells ...

Read More

Python - Contiguous Boolean Range

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

Given a list of boolean values, we are interested to know the positions where contiguous ranges of the same boolean value start and end. This means finding where a sequence of True values begins and ends, and where a sequence of False values begins and ends. Using itertools We can use accumulate along with groupby from the itertools module. The groupby function groups consecutive identical values, and accumulate helps track the cumulative positions where each group ends ? Example from itertools import accumulate, groupby # Given list bool_values = [False, True, True, False, False] ...

Read More

Python - Column deletion from list of lists

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

In a list of lists, an element at the same index of each sublist represents a column-like structure. In this article we will see how to delete a column from a list of lists, which means deleting the element at the same index position from each sublist. Using pop() Method The pop() method removes and returns the element at a specific index. We can use list comprehension to apply pop() to each sublist ? # List of lists representing tabular data data = [[3, 9, 5, 1], [4, ...

Read More

Python - Check if given words appear together in a list of sentence

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

When working with lists of sentences, we often need to check if specific words appear together in any sentence. Python provides several approaches to solve this problem using loops, built-in functions, and functional programming techniques. Using List Comprehension with len() This approach uses list comprehension to find matching words and checks if all target words are present ? sentences = ['Eggs on Sunday', 'Fruits on Monday', 'Eggs and Fruits on Wednesday'] target_words = ['Eggs', 'Fruits'] print("Given list of sentences:") print(sentences) print("Given list of words:") print(target_words) result = [] for sentence in sentences: ...

Read More

Python - Check if all elements in a list are identical

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

There may be occasions when a list contains all identical values. In this article we will see various ways to verify that all elements in a list are the same. Using all() Function We use the all() function to compare each element of the list with the first element. If each comparison returns True, then all elements are identical ? days_a = ['Sun', 'Sun', 'Mon'] result_a = all(x == days_a[0] for x in days_a) if result_a: print("In days_a all elements are same") else: print("In days_a all ...

Read More

Python - Check if a list is contained in another list

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

Given two different Python lists, we need to find if the first list is a part of the second list as a contiguous subsequence. Python provides several approaches to check if one list is contained within another. Using map() and join() We can convert both lists to comma-separated strings using map() and join(), then use the in operator to check containment ? fruits = ['apple', 'banana', 'cherry'] inventory = ['cherry', 'grape', 'apple', 'banana', 'cherry', 'kiwi'] print("Given fruits elements:") print(', '.join(map(str, fruits))) print("Given inventory elements:") print(', '.join(map(str, inventory))) # Convert to strings and check containment ...

Read More

Python - Check if a given string is binary string or not

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

In this article we check if a given string contains only binary digits (0 and 1). We call such strings binary strings. If the string contains any other characters like 2, 3, or letters, we classify it as a non-binary string. Using set() Method The set() function creates a collection of unique characters from a string. We can compare this set with the valid binary characters {'0', '1'} to determine if the string is binary ? def is_binary_string_set(s): binary_chars = {'0', '1'} string_chars = set(s) ...

Read More

Password validation in Python

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

Password validation is essential for securing applications. In this article, we will see how to validate if a given password meets certain complexity requirements using Python's re (regular expression) module. Password Requirements Our validation will check for the following criteria ? At least one lowercase letter (a-z) At least one uppercase letter (A-Z) At least one digit (0-9) At least one special character (@$!%*#?&) Password length between 8 and 18 characters Regular Expression Breakdown The regex pattern ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!#%*?&]{8, 18}$ uses positive lookaheads to ensure all conditions are met ? ^ - ...

Read More

Multi-dimensional lists in Python

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

Lists are a very widely used data structure in Python. They contain a list of elements separated by commas. But sometimes lists can also contain lists within them. These are called nested lists or multidimensional lists. In this article we will see how to create and access elements in a multidimensional list. Creating Multi-dimensional Lists In the below program we create a multidimensional list of 4 columns and 3 rows using nested for loops ? multlist = [[0 for columns in range(4)] for rows in range(3)] print(multlist) The output of the above code is ...

Read More

Launching parallel tasks in Python

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

Parallel processing allows Python programs to break work into independent subprograms that can run simultaneously. This improves performance by utilizing multiple CPU cores and reducing overall execution time. Using multiprocessing Module The multiprocessing module creates child processes that run independently from the main process. Each process has its own memory space and can execute code in parallel ? Basic Process Creation import multiprocessing import time class WorkerProcess(multiprocessing.Process): def __init__(self, process_id): super(WorkerProcess, self).__init__() self.process_id = ...

Read More
Showing 8991–9000 of 25,466 articles
« Prev 1 898 899 900 901 902 2547 Next »
Advertisements