Pradeep Elance

Pradeep Elance

302 Articles Published

Articles by Pradeep Elance

Page 9 of 31

Password validation in Python

Pradeep Elance
Pradeep Elance
Updated on 10-Jul-2020 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

Multi-dimensional lists in Python

Pradeep Elance
Pradeep Elance
Updated on 10-Jul-2020 10K+ Views

Lists are a very widely use data structure in python. They contain a list of elements separated by comma. 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 listIn the below program we create a multidimensional list of 4 columns and 3 rows using nested for loops.Example Live Demomultlist = [[0 for columns in range(4)] for rows in range(3)] print(multlist)OutputRunning the above code gives us the following result −[[0, 0, 0, 0], [0, 0, 0, 0], ...

Read More

Launching parallel tasks in Python

Pradeep Elance
Pradeep Elance
Updated on 10-Jul-2020 434 Views

If a Python program can be broken into subprograms who is processing do not depend on each other, then each of the subprogram can be run in parallel when the overall program is being run. This concept is known as parallel processing in Python.With multiprocessingThis module can be used to create many child processes of a main process which can run in parallel. In the below program we initialize a process and then use the run method to run the multiple sub-processes. We can see different sub processes in the print statement by using the process id. We also use ...

Read More

Importing Data in Python

Pradeep Elance
Pradeep Elance
Updated on 10-Jul-2020 17K+ Views

When running python programs, we need to use datasets for data analysis. Python has various modules which help us in importing the external data in various file formats to a python program. In this example we will see how to import data of various formats to a python program.Import csv fileThe csv module enables us to read each of the row in the file using a comma as a delimiter. We first open the file in read only mode and then assign the delimiter. Finally use a for loop to read each row from the csv file.Exampleimport csv with ...

Read More

Catching the ball game using Python

Pradeep Elance
Pradeep Elance
Updated on 10-Jul-2020 2K+ Views

Python can also be used to create computer games. In this article we will see how the ball catching game can be created using python. In this game a ball keeps falling from the top of a canvas window and a bar is present at the bottom of the window. Two buttons are provided to move the bar in the left and right direction. Using mouse button presss we move the bar at the bottom to catch the falling ball. At different times the ball falls from different positions .ApproachThe approach to build the game is described in the following ...

Read More

Binding function in Python Tkinter

Pradeep Elance
Pradeep Elance
Updated on 10-Jul-2020 2K+ Views

In python tkinter is a GUI library that can be used for various GUI programming. Such applications are useful to build desktop applications. In this article we will see one aspect of the GUI programming called Binding functions. This is about binding events to functions and methods so that when the event occurs that specific function is executed.Binding keyboard eventIn the below example we bind the press of any key from the keyboard with a function that gets executed. Once the Tkinter GUI window is open, we can press any key in the keyboard and we get a message that ...

Read More

Associating a single value with all list items in Python

Pradeep Elance
Pradeep Elance
Updated on 10-Jul-2020 402 Views

We may have a need to associate a given value with each and every element of a list. For example − there are the name of the days and we want to attach the word day as a suffix in them. Such scenarios can be handled in the following ways.With itertools.repeatWe can use the repeat method from itertools module so that the same value is used again and again when paired with the values from the given list using the zip function.Example Live Demofrom itertools import repeat listA = ['Sun', 'Mon', 'Tues'] val = 'day' print ("The Given list : ...

Read More

Standard errno system symbols in Python

Pradeep Elance
Pradeep Elance
Updated on 09-Jul-2020 555 Views

Every programming language has a error handling mechanism in which some errors are already coded into the compiler. In Python we have love which are associated with some standard pre-determined error codes. In this article we will see how to to get the error numbers as well as error codes which are inbuilt. And then take an example of how error code can be used.Error codesIn this program just list out the inbuilt error numbers and error codes. Memorial we use the error no module along with the OS module.Example Live Demoimport errno import os for i in sorted(errno.errorcode):    print(i, ...

Read More

Python Get the numeric prefix of given string

Pradeep Elance
Pradeep Elance
Updated on 09-Jul-2020 444 Views

Suppose we have a string which contains numbers are the beginning. In this article we will see how to get only the numeric part of the string which is fixed at the beginning.With isdigitThe is digit function decides if the part of the string is it digit or not. So we will use takewhile function from itertools to join each part of the string which is a digit.Example Live Demofrom itertools import takewhile # Given string stringA = "347Hello" print("Given string : ", stringA) # Using takewhile res = ''.join(takewhile(str.isdigit, stringA)) # printing resultant string print("Numeric Pefix from the string: ", ...

Read More

Python Get a list as input from user

Pradeep Elance
Pradeep Elance
Updated on 09-Jul-2020 10K+ Views

In this article we will see you how to ask the user to enter elements of a list and finally create the list with those entered values.With format and inputThe format function can be used to fill in the values in the place holders and the input function will capture the value entered by the user. Finally, we will append the elements into the list one by one.ExamplelistA = [] # Input number of elemetns n = int(input("Enter number of elements in the list : ")) # iterating till the range for i in range(0, n):    print("Enter element No-{}: ...

Read More
Showing 81–90 of 302 articles
« Prev 1 7 8 9 10 11 31 Next »
Advertisements