AmitDiwan has Published 10744 Articles

Python – Cross Join every Kth segment

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 07:32:15

225 Views

When it is required to cross join every ‘K’th element, a method is defined that uses iteration and fetches the index as output.ExampleBelow is a demonstration of the same −def merge_pair_elem(my_list_1, my_list_2, K): index_1 = 0 index_2 = 0 while(index_1 < ... Read More

Python program to find the character position of Kth word from a list of strings

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 07:19:06

352 Views

When it is required to find the character position of ‘K’th word from a list of strings, a list comprehension along with enumerate is used.ExampleBelow is a demonstration of the same −my_list = ["python", "is", "fun", "to", "learn"] print("The list is :") print(my_list) K = 15 print("The value ... Read More

Python program to replace all Characters of a List except the given character

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 07:17:39

464 Views

When it is required to replace all characters of a list except a given character, a list comprehension, and the ‘==’ operator are used.ExampleBelow is a demonstration of the same −my_list = ['P', 'Y', 'T', 'H', 'O', 'N', 'P', 'H', 'P'] print("The list is :") print(my_list) replace_char = ... Read More

Python program to concatenate Strings around K

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 07:16:04

170 Views

When it is required to concatenate strings around ‘K’, a simple iteration and the ‘append’ method is used.ExampleBelow is a demonstration of the same −my_list = ["python", "+", 'is', 'fun', "+", 'to', 'learn'] print("The list is :") print(my_list) K = "+" print("The value of K is :") print(K) ... Read More

Python program for sum of consecutive numbers with overlapping in lists

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 07:13:31

638 Views

When it is required to sum the consecutive numbers with overlapping elements in lists, a list comprehension, list slicing, concatenation operator and ‘zip’ methods are used.ExampleBelow is a demonstration of the same −my_list = [41, 27, 53, 12, 29, 32, 16] print("The list is :") print(my_list) my_result = ... Read More

Python program to get the indices of each element of one list in another list

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 07:12:07

251 Views

When it is required to get the indices of each element of one list in another list, a simple iteration and the enumerate attribute along with the ‘setdefault’ method is used.It also uses list comprehension and the ‘get’ method is used.ExampleBelow is a demonstration of the same −my_list = [14, ... Read More

Python program to remove rows with duplicate element in Matrix

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 07:10:25

277 Views

When it is required to remove rows with duplicate element in a matrix, a list comprehension and the ‘set’ operator is used.ExampleBelow is a demonstration of the same −my_list = [[34, 23, 34], [17, 46, 47], [22, 14, 22], [28, 91, 19]] print("The list is :") print(my_list) my_result ... Read More

Python program to extract Keywords from a list

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 07:09:22

820 Views

When it is required to extract keywords from a list, a simple iteration and the ‘iskeyword’ method is used.ExampleBelow is a demonstration of the same −import keyword my_list = ["python", 'is', 'fun', 'to', 'learn'] print("The list is :") print(my_list) my_result = [] for element in my_list: ... Read More

Python program to sort strings by substring range

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 07:07:39

475 Views

When it is required to sort the strings based on a substring range, a method us defined that uses list slicing to determine the result.ExampleBelow is a demonstration of the same −def get_substring(my_string): return my_string[i : j] my_list = ["python", 'is', 'fun', 'to', 'learn'] print("The ... Read More

Python – Extract String elements from Mixed Matrix

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 07:06:36

386 Views

When it is required to extract string elements from mixed matrix, a list comprehension and the ‘isinstance’ method is used.ExampleBelow is a demonstration of the same −my_list = [[35, 66, 31], ["python", 13, "is"], [15, "fun", 14]] print("The list is :") print(my_list) my_result = [element for index in ... Read More

Advertisements