Articles on Trending Technologies

Technical articles with clear explanations and examples

Python – Incremental Slice concatenation in String list

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 206 Views

When it is required to display incremental slice concatenation in string list, a simple iteration and list slicing is used.Below is a demonstration of the same −Examplemy_list = ['pyt', 'is', 'all', 'fun'] print("The list is :") print(my_list) my_result = '' for index in range(len(my_list)):    my_result += my_list[index][:index + 1] print("The result is :") print(my_result)OutputThe list is : ['pyt', 'is', 'all', 'fun'] The result is : pisallfunExplanationA list is defined and displayed on the console.An empty string is created.The list is iterated over, and the element is concatenated with the consecutive element.This result is assigned to ...

Read More

How to divide data frame rows in R by row minimum?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 300 Views

To divide the data frame row values by row minimum in R, we can follow the below steps −First of all, create a data frame.Then, use apply function to divide the data frame row values by row minimum.Create the data frameLet's create a data frame as shown below −x

Read More

Python – Sort Tuples by Total digits

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 319 Views

When it is required to sort tuples by total digits, a method is defined that converts every element in the list to a string, and gets the length of each of these strings, and adds them up. This is displayed as result of the method.Below is a demonstration of the same −Exampledef count_tuple_digits(row):    return sum([len(str(element)) for element in row]) my_tuple = [(32, 14, 65, 723), (13, 26), (12345, ), (137, 234, 314)] print("The tuple is :") print(my_tuple) my_tuple.sort(key = count_tuple_digits) print("The result is :") print(my_tuple)OutputThe tuple is : [(32, 14, 65, 723), (13, 26), (12345, ...

Read More

How to subset rows of an R data frame if any columns have values greater than a certain value?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

To subset rows of an R data frame if any columns have values greater than a certain value, we can follow the below steps −First of all, create a data frame.Then, use filter_all function of dplyr package with any_vars function to subset the rows of the data frame for any columns having values greater than a certain value.Create the data frameLet's create a data frame as shown below −x1

Read More

Python – Extract Row with any Boolean True

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 243 Views

When it is required to extract row with any Boolean True, a list comprehension is used along with the ‘any’ operator.Below is a demonstration of the same −Examplemy_tuple = [[False, True], [False, False], [True, False, True], [False]] print("The tuple is :") print(my_tuple) my_result = [row for row in my_tuple if any(element for element in row)] print("The result is ") print(my_result)OutputThe tuple is : [[False, True], [False, False], [True, False, True], [False]] The result is [[False, True], [True, False, True]]ExplanationA list of list is defined and displayed on the console.A list comprehension is used to check if any ...

Read More

Python – Sort Matrix by Maximum String Length

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 322 Views

When it is required to sort matrix by maximum string length, a method is defined that takes a list as parameter and uses list comprehension and the ‘max’ and ‘len’ methods to determine the result.Below is a demonstration of the same −Exampledef max_length(row):    return max([len(element) for element in row]) my_matrix = [['pyt', 'fun'], ['python'], ['py', 'cool'], ['py', 'ea']] print("The matrix is :") print(my_matrix ) my_matrix .sort(key=max_length) print("The result is :") print(my_matrix )OutputThe matrix is : [['pyt', 'fun'], ['python'], ['py', 'cool'], ['py', 'ea']] The result is : [['py', 'ea'], ['pyt', 'fun'], ['py', 'cool'], ['python']]ExplanationA method named ...

Read More

How to create a scatterplot with two legends using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

If we want to create a scatterplot with two legends then we must be having two categorical or factor columns. This can be done by using the below steps −Creating a data frame with two numerical and two categorical columnsCreating the scatterplot with shape and color argument of geom_point function of ggplot2 packageCreate the data frameLet's create a data frame as shown below −x

Read More

Python – Test for all Even elements in the List for the given Range

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 227 Views

When it is required to test all even elements in the list for the given range, a simple iteration and the modulus operator is used.Below is a demonstration of the same −Examplemy_list = [32, 12, 42, 61, 58, 60, 19, 16] print("The list is :") print(my_list) i, j = 2, 7 my_result = True for index in range(i, j + 1):    if my_list[index] % 2 :       my_result = False       break print("The result is :") if(my_result == True):    print("All The elements are in the given range") else: ...

Read More

How to subset an R data frame based on numerical and categorical column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

Subsetting is one of the commonly used technique which serves many different purposes depending on the objective of analysis. To subset a data frame by excluding a column with the help of dplyr package, we can follow the below steps −Creating a data frame.Subsetting the data frame based on numerical as well as categorical column at the same time with the help of filter function of dplyr package.Create the data frameLet's create a data frame as shown below −Level

Read More

Python – Test String in Character List and vice-versa

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 311 Views

When it is required to test string in character list and vice-versa, a simple ‘in’ operator and ‘join’ method are used.Below is a demonstration of the same −Examplemy_string = 'python' print("The string is :") print(my_string) my_key = ['p', 'y', 't', 'h', 'o', 'n', 't', 'e', 's', 't'] print("The key is ") print(my_key) joined_list = ''.join(my_key) my_result = my_string in joined_list print("The result is :") if(my_result == True):    print("The string is present in the character list") else:    print("The string is not present in the character list")OutputThe string is : python The key is ['p', 'y', ...

Read More
Showing 501–510 of 61,248 articles
« Prev 1 49 50 51 52 53 6125 Next »
Advertisements