Programming Articles - Page 1617 of 3366

Fetching text from Wikipedia’s Infobox in Python

Hafeezul Kareem
Updated on 13-Nov-2020 12:41:01

1K+ Views

In this article, we are going to scrape the text from Wikipedia's Infobox using BeatifulSoup and requests in Python. We can do it in 10 mins. It's straightforward.We need to install bs4 and requests. Execute the below commands to install.pip install bs4 pip install requestsFollow the below steps to write the code to fetch the text that we want from the infobox.Import the bs4 and requests modules.Send an HTTP request to the page that you want to fetch data from using the requests.get() method.Parse the response text using bs4.BeautifulSoup class and store it in a variable.Go to the Wikipedia page ... Read More

CURL context options in PHP

Syed Javed
Updated on 13-Nov-2020 12:18:12

447 Views

IntroductionCURL context options are available when the CURL extension was compiled using the --with-curlwrappers configure option. Given below is list of CURL wrapper context optionsMethodDescriptionmethodHTTP method supported by the remote server. Defaults to GET.headerAdditional headers to be sent during requestuser_agentValue to send with User-Agent: header.contentAdditional data to be sent after the headers. This option is not used for GET or HEAD requests.proxyURI specifying address of proxy server.max_redirectsThe max number of redirects to follow. Defaults to 20.curl_verify_ssl_hostVerify the host. Defaults to FALSE. available for both http and ftp protocol wrappers.curl_verify_ssl_peerRequire verification of SSL certificate used. Defaults to FALSE. available for both ... Read More

Moving Stones Until Consecutive II in C++

Arnab Chakraborty
Updated on 13-Nov-2020 12:05:38

240 Views

Suppose we are considering an infinite number line, here the position of the i−th stone is given by array stones and stones[i] is indicating ith stone position. A stone is an endpoint stone if it has the smallest or largest position. Now in each turn, we pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.If the stones are at say, stones = [1, 2, 5], we cannot move the endpoint stone at position 5, because moving it to any position (such as 0, or 3) will still keep ... Read More

Maximum Sum of Two Non-Overlapping Subarrays in C++

Arnab Chakraborty
Updated on 13-Nov-2020 11:45:44

248 Views

Suppose we have an array A of integers; we have to find the maximum sum of elements in two non−overlapping subarrays. The lengths of these subarrays are L and M.So more precisely we can say that, we have to find the largest V for whichV = (A[i] + A[i+1] + ... + A[i+L-1]) + (A[j] + A[j+1] + ... + A[j+M-1]) and either −0 = 0, decrease i by 1, decrease j by 1, do −rightL[i + 1] := max of temp and x where x is 0 if i + 2 >= n otherwise x = rightL[i + 2]temp ... Read More

How to select multiple DataFrame columns using regexp and datatypes

Kiran P
Updated on 10-Nov-2020 10:04:29

811 Views

DataFrame maybe compared to a data set held in a spreadsheet or a database with rows and columns. DataFrame is a 2D Object.Ok, confused with 1D and 2D terminology ?The major difference between 1D (Series) and 2D (DataFrame) is the number of points of information you need to inorer to arrive at any single data point. If you take an example of a Series, and wanted to extract a value, you only need one point of reference i.e. row index.In comparsion to a table (DataFrame), one point of reference is not sufficient to get to a data point, you need ... Read More

Program to find airports in correct order in Python?

Arnab Chakraborty
Updated on 10-Nov-2020 09:37:21

381 Views

Suppose we have a list of flights as [origin, destination] pairs. The list is shuffled; we have to find all the airports that were visited in the correct order. If there are more than one valid itinerary, return lexicographically smallest ones first.So, if the input is like flights = [["Mumbai", "Kolkata"], ["Delhi", "Mumbai"], ["Kolkata", "Delhi"] ], then the output will be ['Delhi', 'Mumbai', 'Kolkata', 'Delhi']To solve this, we will follow these stepsins := an empty mapouts := an empty mapadj_list := an empty mapDefine a function dfs() . This will take airportwhile outs[airport] is not null, donxt := size of ... Read More

Program to check whether we can make k palindromes from given string characters or not in Python?

Arnab Chakraborty
Updated on 10-Nov-2020 09:34:02

205 Views

Suppose we have a string s and another number k, we have to check whether we can create k palindromes using all characters in s or not.So, if the input is like s = "amledavmel" k = 2, then the output will be True, as we can make "level" and "madam".To solve this, we will follow these stepsd := a map where store each unique characters and their frequencycnt := 0for each key in d, doif d[key] is odd, thencnt := cnt + 1if cnt > k, thenreturn Falsereturn TrueLet us see the following implementation to get better understandingExamplefrom collections ... Read More

Program to find minimum number of Fibonacci numbers to add up to n in Python?

Arnab Chakraborty
Updated on 10-Nov-2020 09:28:33

363 Views

Suppose we have a number n; we have to find the minimum number of Fibonacci numbers required to add up to n.So, if the input is like n = 20, then the output will be 3, as We can use the Fibonacci numbers [2, 5, 13] to sum to 20.To solve this, we will follow these stepsres := 0fibo := a list with values [1, 1]while last element of fibo n, dodelete last element from fibon := n - last element of fibores := res + 1return resLet us see the following implementation to get better understandingExampleclass Solution:   ... Read More

Program to find trailing zeros in factorial of n in C++?

Arnab Chakraborty
Updated on 10-Nov-2020 09:25:30

213 Views

Suppose we have a number n, we have to find the number of trailing zeros of n!.So, if the input is like n = 20, then the output will be 4, as 20! = 2432902008176640000To solve this, we will follow these stepsset count := 0for i := 5, (n/i) > 1, update i := i * 5, docount := count + (n /i)return countLet us see the following implementation to get better understandingExample Live Demo#include #include #define MAX 20 using namespace std; int countTrailingZeros(int n) {    int count = 0;    for (int i = 5; n / i >= 1; i *= 5)       count += n / i;    return count; } main() {    int n = 20;    cout

How to create charts in excel using Python with openpyxl?

Kiran P
Updated on 10-Nov-2020 09:32:41

2K+ Views

In this post, I will show you how to create charts in excel using Python - Openpyxl module. We will create an excel spreadsheet from scratch with Tennis players grandslam titles as the data for creating bar charts using the openpyxl module.Introduction..Microsoft office has started providing a new extension to Microsoft Excel sheets, which is .xlsx, from Office 2007 to support storing more rows and columns.This change had moved Excel sheets to a XML based file format with ZIP compression. The world is ruled by Microsoft spreadsheets, people have been using spreadsheets for various purposes and one of the use ... Read More

Advertisements