Found 33676 Articles for Programming

Prefix matching in Python using pytrie module

Hafeezul Kareem
Updated on 13-Nov-2020 13:03:21

451 Views

In this article, we are going to learn about the pytrie module to prefix matching strings from a list of strings. Let's see an example to understand it clearly.Input: List: ['tutorialspoint', 'tutorials', 'tutorialspython', 'python'] Prefix: 'tutorials' Output: ['tutorialspoint', 'tutorials', 'tutorialspython']We can achieve it in different ways. In this tutorial, we are going to achieve it using the pytrie module.From pytrie module, we will use the pytrie.StringTrie data structure. We can perform create, insert, search, and delete operations.First, install the pytrie module with the following command.pip install pytrieLet's see steps to achieve the desired output.Import the pytrie module.Initialize the list, ... Read More

Form validation using Django

Hafeezul Kareem
Updated on 13-Nov-2020 12:58:00

4K+ Views

In this article, we are going to learn how to validate a form in django. Django comes with build-in validators for forms. We can use them in the tutorial to validate forms.You must familiar with the Django to follow along with this tutorial. If you are not familiar with Django, then this article is not for you.Set up the basic Django project with the following commands.mkdir form_validation cd form_validation python -m venv env (Activate environment based on your OS) pip install django===3.0 django-admin startproject form_validation . (Don't forget dot(.) at the end) python manage.py startapp ... Read More

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

442 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

231 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

240 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

800 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

372 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

196 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

354 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

Advertisements