Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1760 of 2650
1K+ Views
Given a string of characters let's analyse how many of the characters are vowels.With setWe first find out all the individual and unique characters and then test if they are present in the string representing the vowels.Example Live DemostringA = "Tutorialspoint is best" print("Given String: ", stringA) vowels = "AaEeIiOoUu" # Get vowels res = set([each for each in stringA if each in vowels]) print("The vlowels present in the string: ", res)OutputRunning the above code gives us the following result −Given String: Tutorialspoint is best The vlowels present in the string: {'e', 'i', 'a', 'o', 'u'}with fromkeysThis function enables to extract ... Read More
1K+ Views
Here we have a scenario where if string is presented which has elements in it making it a list. But those elements can also represent a key-value pair making it dictionary. In this article we will see how to take such a list string and make it a dictionary.With split and slicingIn this approach we use the split function to separate the elements as key value pair and also use slicing to convert the key value pairs into a dictionary format.Example Live DemostringA = '[Mon:3, Tue:5, Fri:11]' # Given string print("Given string : ", stringA) # Type check print(type(stringA)) # using ... Read More
2K+ Views
Sometimes we can have a list containing strings but the strings themselves are numbers and closing quotes. In such a list we want to convert the string elements into actual integers.With int()The int function takes in parameters and converts it to integers if it is already a number. So we design a for loop to go through each element of the list and apply the in function. We store the final result into a new list.Example Live DemolistA = ['5', '2', '-43', '23'] # Given list print("Given list with strings : ", listA) # using int res = [int(i) for i ... Read More
1K+ Views
Suppose we have a boolean expression, we have to find the result after evaluating that expression.An expression can either be −"t", evaluating to True;"f", evaluating to False;"!(expression)", evaluating to the logical NOT of the inner expression;"&(expr1, expr2, ...)", evaluating to the logical AND of 2 or more inner expressions;"|(expr1, expr2, ...)", evaluating to the logical OR of 2 or more inner expressions;So, if the input is like "|(!(t), &(t, f, t))", then the output will be fasle, this is because !(t) is false, then &(t, f, t) is also false, so the OR of all false values will be false.To ... Read More
5K+ Views
While a Python list contains a series of values a dictionary on the other hand contains a pair of values which are called key-value pairs. In this article we will take two lists and mark them together to create a Python dictionary.With for and removeWe create two nested for loops. In the inner loop will assign one of the list as key for the dictionary while keep removing the values from the list which is outer for loop.Example Live DemolistK = ["Mon", "Tue", "Wed"] listV = [3, 6, 5] # Given lists print("List of K : ", listK) print("list of V ... Read More
262 Views
Python has extensive date and time manipulation capabilities.In this article we'll see in how is string with proper format can we converted to a datetime and the vice versa.With strptimeThis strptime function from datetime module can do the conversion from string to datetime by taking appropriate format specifiers.Example Live Demoimport datetime dt_str = 'September 19 2019 21:02:23 PM' #Given date time print("Given date time: ", dt_str) #Type check print("Data Type: ", type(dt_str)) #Format dtformat = '%B %d %Y %H:%M:%S %p' datetime_val = datetime.datetime.strptime(dt_str, dtformat) print("After converting to date time: ", datetime_val) #Type check print("Data type: ", type(datetime_val)) # Reverting to string ... Read More
650 Views
We may sometime get data which contains strings but the structure of the data inside the stream is a Python list. In this article we will convert string enclosed list to an actual Python list which can be further used in data manipulation.With evalWe know the eval function will give us the actual result which is supplied to it as parameter. So so we supplied the given string to the eval function and get back the Python list.Example Live DemostringA = "['Mon', 2, 'Tue', 4, 'Wed', 3]" # Given string print("Given string : ", stringA) # Type check print(type(stringA)) # using ... Read More
217 Views
Suppose we have two strings str1 and str2, we have to find the shortest string that has both str1 and str2 as subsequences. There may be more than one results, so we will return only one of them.As you know a string S is called a subsequence of string T if deleting some number of characters from T (possibly 0, and the characters are chosen anywhere from T) results in the string S.So, if the input is like "acab", "bac", then the output will be "bacab", this is because two given strings are subsequence of this.To solve this, we will ... Read More
236 Views
Suppose we have a matrix, and a target value, we have to find the number of non-empty submatrices that sum is same as target. Here a submatrix [(x1, y1), (x2, y2)] is the set of all cells matrix[x][y] with x in range x1 and x2 and y in range y1 and y2. Two submatrices [(x1, y1), (x2, y2)] and [(x1', y1'), (x2', y2')] are different if they have some coordinate that is different: like, if x1 is not same as x1'.So, if the input is like010111010and target = 0, then the output will be 4, this is because four 1x1 ... Read More
671 Views
Suppose we have a string S, consider all duplicated contiguous substrings that occur 2 or more times. (The occurrences may overlap.), We have to find the duplicated substring that has the longest possible length. If there is no such substrings, then return a blank string. As the answer may very large, so return in mod 10^9 + 7.So, if the input is like "ababbaba", then the output will be "bab"To solve this, we will follow these steps −m := 1e9 + 7Define a function add(), this will take a, b, return ((a mod m) + (b mod m)) mod mDefine ... Read More