AmitDiwan has Published 10744 Articles

Python Program to get indices of sign change in a list

AmitDiwan

AmitDiwan

Updated on 15-Sep-2021 11:58:50

478 Views

When it is required to get indices of sign change in a list, a simple iteration along with ‘append’ method can be used.ExampleBelow is a demonstration of the samemy_list = [71, 24, -34, -25, -76, 87, 29, -60, 70, 8] print("The list is :") print(my_list) my_result = [] for ... Read More

Python - Restrict Tuples by frequency of first element’s value

AmitDiwan

AmitDiwan

Updated on 15-Sep-2021 11:53:15

223 Views

When it is required to restrict the tuples by frequency of first element’s value, a simple ‘if’ condition along with an iteration and ‘append’ method is used.ExampleBelow is a demonstration of the samemy_list = [(21, 24), (13, 42), (11, 23), (32, 43), (25, 56), (73, 84), (91, 40), (40, 83), ... Read More

Python - Find starting index of all Nested Lists

AmitDiwan

AmitDiwan

Updated on 15-Sep-2021 11:51:38

389 Views

When it is required to find the starting index of all nested lists, a simple iteration along with the ‘append’ method is used.ExampleBelow is a demonstration of the samemy_list = [[51], [91, 22, 36, 44], [25, 25], [46, 67, 78, 82, 69, 29], [ 7, 5]] print("The list is :") ... Read More

Python - Check if list contain particular digits

AmitDiwan

AmitDiwan

Updated on 15-Sep-2021 11:49:55

360 Views

When it is required to check if a list contains particular digits, the ‘join’ method, and a simple iteration are used.ExampleBelow is a demonstration of the samemy_list = [415, 133, 145, 451, 154] print("The list is :") print(my_list) my_digits = [1, 4, 5, 3] digit_string = ''.join([str(ele) for ... Read More

Python - Total equal pairs in List

AmitDiwan

AmitDiwan

Updated on 15-Sep-2021 11:47:57

649 Views

When it is required to find the total equal pairs in a list, the ‘set’ operator and the ‘//’ operator along with an iteration can be used.ExampleBelow is a demonstration of the samemy_list = [34, 56, 12, 32, 78, 99, 67, 34, 52, 78, 99, 10, 0, 11, 23, 9] ... Read More

Python program to return rows that have element at a specified index

AmitDiwan

AmitDiwan

Updated on 15-Sep-2021 11:44:08

192 Views

When it is required to return rows that have an element at a specified index, a simple iteration and the ‘append’ function can be used.ExampleBelow is a demonstration of the samemy_list_1 = [[21, 81, 35], [91, 14, 0], [64, 61, 42]] my_list_2 = [[21, 92, 63], [80, 19, 65], [54, ... Read More

Python Program to find the Next Nearest element in a Matrix

AmitDiwan

AmitDiwan

Updated on 15-Sep-2021 11:42:27

173 Views

When it is required to find the next nearest element in a matrix, a method is defined tat iterates through the list and places a specific condition. This method is called and the results are displayed.ExampleBelow is a demonstration of the samedef get_nearest_elem(my_list, x, y, my_key):    for index, row ... Read More

Python program to find the redundancy rates for each row of a matrix

AmitDiwan

AmitDiwan

Updated on 15-Sep-2021 11:40:56

317 Views

When it is required to find the redundancy rates for every row of a matrix, a simple iteration and the ‘append’ method can be used.ExampleBelow is a demonstration of the samemy_list = [[91, 52, 12, 29, 33], [54, 54, 54, 54, 54], [11, 22, 33, 59, 95]] print("The list ... Read More

Python - Change the signs of elements of tuples in a list

AmitDiwan

AmitDiwan

Updated on 15-Sep-2021 11:36:50

361 Views

When it is required to change the signs of the elements in a list of tuple, a simple iteration, the ‘abs’ method and the ‘append’ method can be used.ExampleBelow is a demonstration of the samemy_list = [(51, -11), (-24, -24), (11, 42), (-12, 45), (-45, 26), (-97, -4)] print("The ... Read More

Python program to convert a list to a set based on a common element

AmitDiwan

AmitDiwan

Updated on 15-Sep-2021 11:35:21

134 Views

When it is required to convert a list to a set based on a specific common element, a method can be defined that iterates through the set using ‘enumerate’ and places a specific condition on the elements. The ‘union’ method and the ‘map’ methods are used.ExampleBelow is a demonstration of ... Read More

Advertisements