Found 10804 Articles for Python

Morse Code Translator in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

Morse Code Translator is used in Cryptography. It is named by Samuel F. B. Morse. By this technique we convert a message to a series of dots, commas, "-", "/". This technique is very simple. Every alphabet in English signifies a series of ".", ", ", "/", "-". We just encrypt the message from message to symbols and decrypt from symbols to English. The dictionary is given below 'A':'.-', 'B':'-...', 'C':'-.-.', 'D':'-..', 'E':'.', 'F':'..-.', 'G':'--.', 'H':'....', 'I':'..', 'J':'.---', 'K':'-.-', 'L':'.-..', 'M':'--', 'N':'-.', 'O':'---', 'P':'.--.', 'Q':'--.-', 'R':'.-.', 'S':'...', 'T':'-', 'U':'..-', 'V':'...-', 'W':'.--', 'X':'-..-', 'Y':'-.--', 'Z':'--..', '1':'.----', '2':'..---', '3':'...--', '4':'....-', '5':'.....', ... Read More

Using CX_Freeze in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

856 Views

Sometimes we feel to create something different which is very exciting, and according to human nature, we always love to share it. Python also fulfills those wishes. Using Python, if we want to share our Python program with our friends we can do that, only need to have the same version of Python installed with all the modules those are used in program of their machine. First we need to install CX_Freeze module using pip install CX_Frezze command in command prompt. First step is to solve this assignment, a python program conversion. We need standard library modules, here we ... Read More

Multiprocessing In Python

Samual Sam
Updated on 26-Jun-2020 12:43:27

4K+ Views

The multiprocessing package supports spawning processes. It refers to a function that loads and executes a new child processes. For the child to terminate or to continue executing concurrent computing, then the current process hasto wait using an API, which is similar to threading module.IntroductionWhen we work with Multiprocessing, at first we create process object. Then it calls a start() method.Example codefrom multiprocessing import Process    def display():       print ('Hi !! I am Python')       if __name__ == '__main__':       p = Process(target=display)       p.start()       p.join()In this example, ... Read More

Tweet using Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

125 Views

Before using Tweet in Python, we have to follow some steps. Step1 − at first we must have a tweeter profile and then it has to be added with our mobile number. First go to - Settings -> Add Phone -> Add number -> Confirm -> Save. We have to follow these steps. Then turn off all text notifications. Step2 − Set up a new app. Follow − Twitter Apps -> Create New App -> Leave Callback URL empty -> Create Twitter application. Then display message "Your application has been created. You review and adjust your application's settings". Step3 − ... Read More

Synchronization and Pooling of processes in Python

Samual Sam
Updated on 26-Jun-2020 12:44:50

574 Views

Synchronization between processesMultiprocessing is a package which supports spawning processes using an API. This package is used for both local and remote concurrencies. Using this module, programmer can use multiple processors on a given machine. It runs on Windows and UNIX os.All equivalent synchronization primitives are present in this package.Example codefrom multiprocessing import Process, Lock    def my_function(x, y):       x.acquire()       print ('hello world', y)       x.release()       if __name__ == '__main__':       lock = Lock()    for num in range(10): Process(target= my_function, args=(lock, num)).start()Here one instance can lock ... Read More

Plotting solar image in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

245 Views

In Python provides SunPy package for create solar image. In this package has different files which are solar data of proton/electron fluxes from various solar observatory and solar labs. Using pip install sunpy command, we can install sunpy package. Here we plot a sample AIA image. AIA is Atmospheric Imaging Assembly. This is another instrument board of the SDO. Here we use sunpy.Map() function to create a map from one of the supported data products. Example code import sunpy.map import matplotlib.pyplot as plt import sunpy.data.sample my_aia = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE) fig = plt.figure() ax = plt.subplot(111, projection=my_aia) my_aia.plot() my_aia.draw_limb() ... Read More

Scraping and Finding Ordered Word in a Dictionary in Python

karthikeya Boyini
Updated on 26-Jun-2020 12:37:10

498 Views

For solving this problem we need requests module.For installing requests module, we need this command to get executed at command line.pip install requestsScrapingImport requests module.Then we need to fetch data from URL.Using UTF-8 decode the text.Then convert string into a list of words.Ordered FindingTraverse the list of words using loop.Then compare the ASCII value of adjacent character of each word.If the comparison is true then print ordered word otherwise store the unordered word.Example codeimport requests    def Words_find():       my_url = ""#put thisurl of .txt files in any website       my_fetchData = requests.get(my_url)       ... Read More

Ways to sort list of dictionaries by values in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

135 Views

Here one dictionary is given, our task is to sort by their values. Two values are present in this dictionary one is name and another is roll. First we display sorted list by their roll using lambda function and in-built sorted function. Second we display sorted list by the name and roll and third by their name. Example code Live Demo # Initializing list of dictionaries my_list1 = [{ "name" : "Adwaita", "roll" : 100}, { "name" : "Aadrika", "roll" : 234 }, { "name" : "Sakya" , "roll" : 23 }] print ("The list is sorted ... Read More

Matrix manipulation in Python

AmitDiwan
Updated on 11-Aug-2022 11:24:53

14K+ Views

We can easily perform matrix manipulation in Python using the Numpy library. NumPy is a Python package. It stands for 'Numerical Python'. It is a library consisting of multidimensional array objects and a collection of routines for processing of array. Using NumPy, mathematical and logical operations on arrays can be performed. Install and Import Numpy To install Numpy, use pip − pip install numpy Import Numpy − import numpy Add, Subtract, Divide and Multiply matrices We will use the following Numpy methods for matrix manipulations − numpy.add() − Add two matrices numpy.subtract() − Subtract two matrices numpy.divide() ... Read More

Underscore(_) in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

507 Views

In Python in some cases we use Single Underscore(_) and some cases we use Double Underscores (__). In Python has following cases, where we use underscore. If we want to store the value of last expression in interpreter. If we want to ignore some values. For declaration of variable or function. To separate digits of number lateral value. It is also used as ‘Internationalization (i18n)’ or ‘Localization (l10n)’ functions. Now some examples on every cases. Used in interpreter The Python Interpreter stores the last expression value in the '_'. >>> 20 20 >>> _ ... Read More

Advertisements