Python Articles

Page 129 of 852

Password validation in Python

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

It is a general requirement to have a reasonably complex password. In this article we will see how to validate if a given password meats certain level of complexity. For that will use the regular expression module known as re.Example -1First we create a regular expression which can satisfy the conditions required to call it a valid password. Then we e match the given password with the required condition using the search function of re. In the below example the complexity requirement is we need at least one capital letter, one number and one special character. We also need the ...

Read More

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

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

In this article we check if a given string has characters which are only 1 or 0. We call such strings as binary strings. If it has any other digit like 2 or 3 etc., we classify it as a non-binary string.With setThe set operator in python stores only unique elements. So we take a string and apply the set function to it. Then we create another set which has only 0 and 1 as its elements. If both these sets are equal then the string is definitely binary. Also the string may have only 1s or only 0s. So ...

Read More

Python - Check if a list is contained in another list

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

Given two different python lists we need to find if the first list is a part of the second list.With map and joinWe can first apply the map function to get the elements of the list and then apply the join function to cerate a comma separated list of values. Next we use the in operator to find out if the first list is part of the second list.ExamplelistA = ['x', 'y', 't'] listB = ['t', 'z', 'a', 'x', 'y', 't'] print("Given listA elemnts: ") print(', '.join(map(str, listA))) print("Given listB elemnts:") print(', '.join(map(str, listB))) res = ', '.join(map(str, listA)) ...

Read More

Python - Check if all elements in a list are identical

Pradeep Elance
Pradeep Elance
Updated on 11-Mar-2026 986 Views

There may be occasions when a list will contain all the values which are same. In this article we will see various way to verify that.With allWe use the all function to find the result of comparison of each element of the list with the first element. If each comparison gives a result of equality then the result is given as all elements are equal else all elements are not equal.ExamplelistA = ['Sun', 'Sun', 'Mon'] resA = all(x == listA[0] for x in listA) if resA:    print("in ListA all elements are same") else:    print("In listA all ...

Read More

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

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

Say we have a list containing small sentences as its elements. We have another list which contains some of the words used in this sentences of the first list. We want to find out if two words from the second list are present together in some of the sentences of the first list or not.With append and for loopWe use the for loop with in condition to check for the presence of words in the lists of sentences. Then we use the len function to check if we have reached the end of the list.Examplelist_sen = ['Eggs on Sunday', 'Fruits ...

Read More

Python - Column deletion from list of lists

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

In a list of lists an element at the same index of each of the sublist represents a column like structure. In this article we will see how we can delete a column from a list of lists. Which means we have to delete the element at the same index position from each of the sublist.Using popWe use the pop method which removes the element at a particular position. A for loop is designed to iterate through elements at specific index and removes them using pop.Example# List of lists listA = [[3, 9, 5, 1], [4, 6, 1, 2], [1, ...

Read More

Python - Contiguous Boolean Range

Pradeep Elance
Pradeep Elance
Updated on 11-Mar-2026 395 Views

Given a list of values, we are interested to know at which position are the Boolean values present as a contiguous list. Which means after we encounter a value which is TRUE there is a continuous value of true from that position until FALSE value is found. Similarly when a FALSE is found there is a contiguous value of FALSE until TRUE is found.With itertoolsW can use accumulate along with groupby from the itertools module. In this example we take a given list and then apply the accumulate function to keep track of the values that are brought together using ...

Read More

self in Python class

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 2K+ Views

In this tutorial, we are going to learn about the self in Python. You must be familiar with it if you are working with Python. We will see some interesting things about.Note − self is not a keyword in Python.Let's start with the most common usage of self in Python.We'll use self in classes to represent the instance of an object. We can create multiple of a class and each instance will have different values. And self helps us to get those property values within the class instance. Let's see ane example.Example# class class Laptop:    # init method   ...

Read More

Set update() in Python to do union of n arrays

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 365 Views

In this tutorial, we are going to write a program that uses set update method to union multiple arrays. And it will return a resultant one-dimension array with all unique values from the arrays.Let's see an example to understand it more clearly.Let's see an example to understand it more clearly.Inputarrays = [[1, 2, 3, 4, 5], [6, 7, 8, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]Output[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]Follow the below steps to write the program.Initialize the array as shown in the example.3Create an empty.Iterate over ...

Read More

Split a string in equal parts (grouper in Python)

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 399 Views

In this tutorial, we are going to write a program that splits the given string into equal parts. Let's see an example.Inputstring = 'Tutorialspoint' each_part_length = 5OutputTutor ialsp ointXInputstring = 'Tutorialspoint' each_part_length = 6OutputTutori alspoi ntXXXX We are going to use the zip_longest method from the itertools module to achieve the result.The method zip_longest takes iterators as argument. We can also pass the fillvalue for partitioning the string. It will return list of tuples that contains characters of equal number.The zip_longest return a tuple on each iteration until the longest iterator in the given in exhausted. And the tuple contains ...

Read More
Showing 1281–1290 of 8,519 articles
« Prev 1 127 128 129 130 131 852 Next »
Advertisements