Found 10784 Articles for Python

Python Program to extract email-id from URL text file

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

264 Views

Here we are using regular expression package for extracting email-id from the URL-text file. Given the URL- text file. Using regular expression package we define the pattern of email-id then use findall() function, using this method to check the text which will match with this pattern. Input text= Please contact us at contact@tutorialspoint.com for further information."+\ " You can also give feedback at feedback@tutorialspoint.com" Output ['contact@tutorialspoint.com ', 'feedback@tutorialspoint.com'] Example code import re my_text = "Please contact us at contact@tutorialspoint.com for further information."+\ " You can also give feedback at feedback@tutorialspoint.com" my_emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", ... Read More

Python program to convert float decimal to octal number

AmitDiwan
Updated on 12-Aug-2022 11:57:33

484 Views

Octal Number uses eight digits, 0, 1, 2, 3, 4, 5, 6, 7. Also called as base 8 number system. Each position in an octal number represents a 0 power of the base (8). Last position in an octal number represents a x power of the base (8). Decimal number system has base 10 as it uses 10 digits from 0 to 9. In decimal number system, the successive positions to the left of the decimal point represent units, tens, hundreds, thousands, and so on. Given a float decimal value and input the decimal places number, our task is to ... Read More

Python program to convert floating to binary

AmitDiwan
Updated on 12-Aug-2022 11:54:31

3K+ Views

In this article, we will see how to convert floating-point value to binary. Binary uses two digits, 0 and 1. Also called as base 2 number system Each position in a binary number represents a 0 power of the base (2). Last position in a binary number represents a x power of the base (2). First, we take the integer part from the floating point value and convert it to binary then take fractional part and convert it to binary form and lastly combining both. Let’s say we have the following floating point number − 22.625 Convert decimal 22 ... Read More

Python program to right rotate a list by n

AmitDiwan
Updated on 11-Aug-2022 11:29:49

2K+ Views

In this article, we will see how to right rotate a list from the given rotation number. A list has comma-separated values (items) between square brackets. Important thing about a list is that the items in a list need not be of the same type Let’s say the following is our input list − myList = [5, 20, 34, 67, 89, 94, 98, 110] The following is the output with n = 4 − 89, 94, 98, 110, 5, 20, 34, 67 Right rotate a list by n using slicing Here, slicing is used to right rotate a ... Read More

Get similar words suggestion using Enchant in Python

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

272 Views

When we write something, many times happen with us that we misspelled some words. To overcome this problem, Python provides Enchant module. This is mainly used to check the spelling of words and suggest corrections for words that are miss-spelled. It is also used in many popular spellchecking packages to perform this task, including ispell, aspell and MySpell. It is very flexible at handling multiple dictionaries and multiple languages. For installing this, we use this command line in command prompt. pip install pyenchant Example Input >>> import enchant >>> d.suggest("prfomnc") Output::['prominence', 'performance', 'preform', 'Provence', 'preferment', 'proforma'] Example code ... Read More

Python Implementation of automatic Tic Tac Toe game using random number

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

470 Views

This is very funny game. In this game no player is needed, it is an automatic game. Here we are using two Python modules numpy and random. In this game the mark on the board is put automatically instead of asking the user to put a mark on the board, and it will display the board after each turn unless a player wins. It returns -1 If the game gets draw. Example code import numpy as np import random from time import sleep # first creates an empty board def my_create_board(): return(np.array([[0, 0, 0], [0, ... Read More

Thread-based parallelism in Python

Samual Sam
Updated on 26-Jun-2020 12:51:03

311 Views

A thread in computer science is a set of instructions that can be managed independently by a scheduler, which is a part of operating system.The main function of Threading is to run multiple threads at a time. Threads means different tasks, function calls in the program and multiple threads run at the same time that does not means that they are executed on different machines.Multi-threading is used in two cases.When the outputs of the sub-programs need to combined with main program.When main program contains piece of code that are relatively independent of each other.Threading modulePython provides Threading module which is ... Read More

Text Analysis in Python3

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

184 Views

In this assignment we work with files. Files are everywhere in this Universe. In computer system files are essential part. Operating system consists a lot of files. Python has two types of files-Text Files and Binary Files. Here we discuss about Text Files Here we focus some of the important functions on files. Number of words Number of characters Average word length Number of stop words Number of special characters Number of numeric Number of uppercase words We have a test file "css3.txt", we are working on that file Number of words When we count number of ... Read More

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

880 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

Advertisements