Found 10476 Articles for Python

Fetching top news using news API in Python

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

703 Views

News API is very famous API for searching and fetching news articles from any web site, using this API anyone can fetch top 10 heading line of news from any web site. But using this API, one thing is required which is the API key. Example Code import requests def Topnews(): # BBC news api my_api_key="Api_number” my_url = = " https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=my_api_key" my_open_bbc_page = requests.get(my_url).json() my_article = my_open_bbc_page["articles"] my_results = [] for ar in my_article: ... Read More

Minkowski distance in Python

Sumana Challa
Updated on 11-Jun-2025 14:47:47

2K+ Views

Minkowski distance is a metric in a normed vector space that measures the distance between two or more vectors. This is typically used in machine learning to find distance similarity. The formula to calculate the Minkowski distance is - $$\mathrm{D= \big[\sum_{i=1}^{n}|r_i-s_i|^p\big]^{1/p}}$$ Where, xi and yi: Two points in n-dimensional space p: Parameter that determines the type of distance being calculated. For example, if p=1, it is the Manhattan distance, and if p=2, it represents Euclidean distance. For example, if we consider the following vector's as input - x = (0, ... Read More

Python Program to extract email-id from URL text file

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

337 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 floating to binary

Sumana Challa
Updated on 09-Jun-2025 14:26:50

3K+ Views

Floating number is a number that has a decimal point and can represent both large and very small values. Binary number is a number expressed in the base-2 numeral system, using 0's and 1's. The conversion of floating-point number to binary representation in Python requires to represent the number in the IEEE 754 format(a set of representation of numerical values and symbols). For example, consider a floating number 9.87, its IEEE 754 32-bit binary representation (1 bit for the sign, 8 bits for exponent, and 23 bits for the significand) is "01000001000111011110101110000101". In this article, we will discuss different ways ... Read More

Python program to right rotate a list by n

Sumana Challa
Updated on 05-Jun-2025 13:52:02

2K+ Views

In this article, we will discuss different methods used to right rotate a list from the given rotation number. A list has comma-separated values (items) of same type or different type between square brackets. To right rotate a list by n, Python offers many ways such as using slicing, rotate() method of the deque object and others. Let's discuss these ways in detail with examples - myList = [5, 20, 34, 67, 89, 94, 98, 110] The following is the output if we assign n as 4 − 89, 94, 98, 110, 5, 20, 34, 67 Right ... Read More

Get similar words suggestion using Enchant in Python

Sumana Challa
Updated on 11-Jun-2025 14:57:14

399 Views

There will be times when we misspell some words when we write something. To overcome this problem, we use the PyEnchant module in Python. This module is used to check the spelling of words and suggest corrections that are misspelled words. It is also used in many popular tasks, including ispell, aspell, and MySpell. It is very flexible in handling multiple dictionaries and multiple languages. For example, if the input is 'prfomnc', then the output returned would be - 'prominence', 'performance', 'preform', 'provence', 'preferment', 'proforma'. PyEnchant Module For Windows users, install the pre-built binary packages using pip - pip ... Read More

Python Implementation of automatic Tic Tac Toe game using random number

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

1K+ 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

Text Analysis in Python3

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

286 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

3K+ 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

1K+ 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