Found 26504 Articles for Server Side Programming

CGI Environment Variables in Python

Mohd Mohtashim
Updated on 31-Jan-2020 07:48:09

2K+ Views

All the CGI programs have access to the following environment variables. These variables play an important role while writing any CGI program.Sr.No.Variable Name & Description1CONTENT_TYPEThe data type of the content. Used when the client is sending attached content to the server. For example, file upload.2CONTENT_LENGTHThe length of the query information. It is available only for POST requests.3HTTP_COOKIEReturns the set cookies in the form of key & value pair.4HTTP_USER_AGENTThe User-Agent request-header field contains information about the user agent originating the request. It is name of the web browser.5PATH_INFOThe path for the CGI script.6QUERY_STRINGThe URL-encoded information that is sent with GET method ... Read More

Special Syntax with Parentheses in Python

Mohd Mohtashim
Updated on 31-Jan-2020 07:44:14

175 Views

Sr.No.Example & Description1R(?#comment)Matches "R". All the rest is a comment2R(?i)ubyCase-insensitive while matching "uby"3R(?i:uby)Same as above4rub(?:y|le))Group only without creating \1 backreference

Regular Expression Examples in Python

Mohd Mohtashim
Updated on 31-Jan-2020 07:51:02

331 Views

Literal charactersSr.No.Example & Description1pythonMatches beginning of line.Character classesSr.No.Example & Description1[Pp]ythonMatch "Python" or "python"2rub[ye]Match "ruby" or "rube"3[aeiou]Match any one lowercase vowel4[0-9]Match any digit; same as [0123456789]5[a-z]Match any lowercase ASCII letter6[A-Z]Match any uppercase ASCII letter7[a-zA-Z0-9]Match any of the above8[^aeiou]Match anything other than a lowercase vowel9[^0-9]Match anything other than a digitSpecial Character ClassesSr.No.Example & Description1.Match any character except newline2\dMatch a digit: [0-9]3\DMatch a nondigit: [^0-9]4\sMatch a whitespace character: [ \t\r\f]5\SMatch nonwhitespace: [^ \t\r\f]6\wMatch a single word character: [A-Za-z0-9_]7\WMatch a nonword character: [^A-Za-z0-9_]Repetition CasesSr.No.Example & Description1ruby?Match "rub" or "ruby": the y is optional2ruby*Match "rub" plus 0 or more ys3ruby+Match "rub" plus 1 or more ... Read More

Valid Parenthesis String in C++

Arnab Chakraborty
Updated on 28-Apr-2020 07:02:40

1K+ Views

Suppose we have an expression. The expression has some parentheses; we have to check the parentheses are balanced or not. The order of the parentheses are (), {} and []. Suppose there are two strings. “()[(){()}]” this is valid, but “{[}]” is invalid.To solve this, we will follow these steps −Traverse through the expression until it has exhaustedif the current character is opening bracket like (, { or [, then push into stackif the current character is closing bracket like ), } or ], then pop from stack, andcheck whether the popped bracket is corresponding starting bracket of thecurrent character, ... Read More

Counting Bits in Python

Arnab Chakraborty
Updated on 28-Apr-2020 06:59:03

2K+ Views

Suppose we have a non-negative integer number num. For each number i in the range 0 ≤ i ≤ num we have to calculate the number of 1's in their binary counterpart and return them as a list. So if the number is 5, then the numbers are [0, 1, 2, 3, 4, 5], and number of 1s in these numbers are [0, 1, 1, 2, 1, 2]To solve this, we will follow these steps −res := an array which holds num + 1 number of 0soffset := 0for i in range 1 to num + 1if i and i ... Read More

Largest Number in Python

Arnab Chakraborty
Updated on 28-Apr-2020 06:55:35

585 Views

Suppose there is a list of non-negative integers, we have to arrange them such that they form the largest number. So if the array is [10, 2], then the largest number will be 210.To solve this, we will follow these steps −Arrange the numbers where the most significant digits are greater than place them at first, like this arrangement the numbers. After that just join the numbers from the array.ExampleLet us see the following implementation to get a better understanding − Live Demofrom functools import cmp_to_key class Solution(object):    def largestNumber(self, nums):       for i in range(len(nums)):     ... Read More

Evaluate Reverse Polish Notation in C++ Program

Arnab Chakraborty
Updated on 28-Apr-2020 06:44:43

6K+ Views

Suppose we have Reverse polish notation and we have to evaluate the value. The reverse polish notation is also known as postfix expression. Here we have to use the stack data structure to solve the postfix expressions.From the postfix expression, when some operands are found, pushed them in the stack. When some operator is found, two items are popped from stack and then the operation is performed in the correct sequence. After that, the result is also pushed in the stack for future use. After completing the whole expression, the final result is also stored in the stack top. So ... Read More

Word Break in Python

Arnab Chakraborty
Updated on 28-Apr-2020 06:39:14

973 Views

Suppose we have one non-empty string s and a dictionary wordDict. That is containing a list of non-empty words, determine when s can be segmented into a space-separated sequence of one or more dictionary words. We have to follow some rules −The same word in the dictionary may be reused multiple numbers of times in the segmentation.We can assume that the dictionary does not contain duplicate words.Suppose the string s = “applepenapple”, and word dictionary is like [“apple”, “pen”], then the output will be true because the string s can be segmented as “apple pen apple”.Let us see the steps ... Read More

Gas Station in C++

Arnab Chakraborty
Updated on 28-Apr-2020 06:33:33

620 Views

Suppose there is a circle, and there are n gas stations on the circle. We have two sets of data like −The amount of gas that every gas stations hasDistance from one gas stations to another.Calculate the first point, from where a car will be able to complete the circle. Assume for 1 unit of gas, the car can go 1 unit of distance. Suppose there are four gas stations, and the amount of gas, and distance from the next gas stations is as like [(4, 6), (6, 5), (7, 3), (4, 5)], the first point from where car can ... Read More

Palindrome Partitioning in C++

Arnab Chakraborty
Updated on 28-Apr-2020 06:28:15

440 Views

Suppose we have one input string, a partitioning of that string is palindrome partitioning, when every substring of the partition is a palindrome. In this section, we have to find the minimum cuts are needed to palindrome partitioning the given string. So if the string is like “ababbbabbababa” Minimum cut to partition as palindrome. Here 3 cuts are needed. The palindromes are: a | babbbab | b | ababaTo solve this, we will follow these steps −n := length of strdefine cut matrix and pal matrix each of order n x nfor i := 0 to n, dopal[i, i] := ... Read More

Advertisements