Found 26504 Articles for Server Side Programming

Check order specific data type in tuple in Python

AmitDiwan
Updated on 12-Mar-2021 06:04:02

452 Views

When it is required to check the order of a specific data type in a tuple, the 'isinstance' method and the 'chained if' can be used.The 'isinstance' method checks to see if a given parameter belong to a specific data type or not.The 'chained if' is a chained conditional statement. It is a different way of writing nested selection statements. It basically means multiple if statements are combined using 'and' operator, and their result is evaluated.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).Below is a ... Read More

Find maximum sum array of length less than or equal to m in C++

sudhir sharma
Updated on 12-Mar-2021 06:23:44

159 Views

In the problem, we are given n arrays of different length. Our task is to Find the maximum sum array of length less than or equal to m.We need to find sub-arrays from the arrays to maximise the sum and make the length of all subarrays combined equal to m.Let’s take an example to understand the problem, Inputn = 3, m = 4 arrOfArr[][] = {    {5, 2, -1, 4, -3}    {3, -2, 1, 6}    {-2, 0, 5} }Output20ExplanationSubArrays are {5, 4}, {6}, {5}, length = 2 + 1 + 1 = 4 Sum = 5 + ... Read More

Convert location coordinates to tuple in Python

AmitDiwan
Updated on 12-Mar-2021 06:02:34

487 Views

When it is required to convert the location co-ordinates into a tuple format, the 'eval' method can be used.The 'eval' method parses the expression which is passed to it as an argument. It executes that arguments as the code. It returns the result which is evaluated from the 'expression', i.e the parameter.Below is a demonstration of the same −ExampleLive Demomy_string = "67.5378, -78.8523" print("The string is : ") print(my_string) my_result = eval(my_string) print("The coordinates after converting the string to tuple is : ") print(my_result)OutputThe string is : 67.5378, -78.8523 The coordinates after converting the string to tuple ... Read More

Remove duplicate lists in tuples (Preserving Order) in Python

AmitDiwan
Updated on 12-Mar-2021 06:02:00

258 Views

When it is required to remove the duplicates present in tuple of list, as well as preserving the order, a list comprehension and the 'set' method can be used.The list comprehension is a shorthand to iterate through the list and perform operations on it.Python comes with a datatype known as 'set'. This 'set' contains elements that are unique only. The set is useful in performing operations such as intersection, difference, union and symmetric difference.Below is a demonstration of the same −ExampleLive Demomy_tuple_1 = ([1, 21, 34] , [11, 0, 98], [45, 67, 56]) print("The tuple of list is : ... Read More

Intersection in Tuple Records Data in Python

AmitDiwan
Updated on 12-Mar-2021 05:59:14

579 Views

When it is required to find the intersection of data in tuple records, a list comprehension can be used.The list comprehension is a shorthand to iterate through the list and perform operations on it.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in a list. Below is a demonstration of the same −ExampleLive Demomy_list_1 = [('Hi', 1) , ('there', 11), ('Will', 56)] my_list_2 = [('Hi', 1) ,('are', 7) ,('you', 10)] print("The first list is : ") print(my_list_1) print("The ... Read More

Find Maximum side length of square in a Matrix in C++

sudhir sharma
Updated on 12-Mar-2021 06:00:41

276 Views

In this problem, we are given a 2-D matrix mat[][] of size n, n being an odd number. Our task is to Find Maximum side length of a square in a Matrix.Problem Description − We need to find the length of the square matrix whose perimeter values are the same and it shares the same center as the matrix.Let’s take an example to understand the problem, Inputmat[][] = {    {2, 4, 6, 6, 5},    {1, 7, 7, 7, 3},    {5, 7, 0, 7, 1},    {3, 7, 7, 7, 1},    {2, 0, 1, 3, 2} }Output3Solution ... Read More

Check if tuple and list are identical in Python

AmitDiwan
Updated on 12-Mar-2021 05:57:05

333 Views

When it is required to check if a tuple and a list are identical, i.e they contain same elements, a simple loop can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).Below is a demonstration of the same −ExampleLive Demomy_tuple_1 = ('Hi' , 'there', 'Will') my_list = ['How' ,'are' ,'you'] print("The tuple is : ") print(my_tuple_1) print("The list is : ") print(my_list) my_result = True for i in range(0, len(my_list)):    if(my_list[i] != my_tuple_1[i]):       my_result = False       ... Read More

Common words among tuple strings in Python

AmitDiwan
Updated on 12-Mar-2021 05:56:13

327 Views

When it is required to find common words among the tuple strings, the 'join' method, the 'set' method, the '&' operator and the 'split' method is used.The 'join' method can be used to join multiple values based on a specific value, Python comes with a datatype known as 'set'. This 'set' contains elements that are unique only. The set is useful in performing operations such as intersection, difference, union and symmetric difference.The 'split' function splits the given data into multiple sections depending on the value on which it needs to be split.The '&' operator performs multiplication, i.e AND operation.Below is ... Read More

Ways to concatenate tuples in Python

AmitDiwan
Updated on 12-Mar-2021 05:55:19

6K+ Views

When it is required to concatenate multiple tuples, the '+' operator can be used. A tuple is an immutable data type. It means, values once defined can't be changed by accessing their index elements. If we try to change the elements, it results in an error. They are important contains since they ensure read-only access.The '+' operator can be used to add numeric values or concatenate strings.Below is a demonstration of the same −ExampleLive Demomy_tuple_1 = (11, 14, 0, 78, 33, 11) my_tuple_2 = (10, 78, 0, 56, 8, 34) print("The first tuple is : ") print(my_tuple_1) print("The second ... Read More

Find maximum possible stolen value from houses in C++

sudhir sharma
Updated on 12-Mar-2021 05:57:40

695 Views

In this problem, we are given n houses with some values in them. Our task is to Find the maximum possible stolen value from houses.Problem Description − We have an array houses[] that consist of the values that are in each house. A thief robs the houses but he cannot steal from two adjacent houses as neighbours know about the theft. We need to find the maximum possible value that can be stolen by the thief from the house without getting caught.Let’s take an example to understand the problem, Inputhouses[] = {5, 2, 1, 6, 7, 9, 4, 3}Output23ExplanationThe max ... Read More

Advertisements