AmitDiwan has Published 10744 Articles

Python program to print Rows where all its Elements’ frequency is greater than K

AmitDiwan

AmitDiwan

Updated on 07-Sep-2021 12:56:19

182 Views

When it is required to print rows where all its elements’ frequency is greater than K, a method is defined that takes two parameters, and uses ‘all’ operator and iteration to give the result.Below is a demonstration of the same −Exampledef frequency_greater_K(row, K) : return all(row.count(element) > ... Read More

Python Program to repeat elements at custom indices

AmitDiwan

AmitDiwan

Updated on 07-Sep-2021 12:22:36

98 Views

When it is required to repeat elements at custom indices, a simple iteration, enumerate attribute, the ‘extend’ method and the ‘append’ method are used.Below is a demonstration of the same −Examplemy_list = [34, 56, 77, 23, 31, 29, 62, 99] print("The list is :") print(my_list) index_list = [3, 1, 4, ... Read More

Python Program to Find the Fibonacci Series Using Recursion

AmitDiwan

AmitDiwan

Updated on 07-Sep-2021 10:59:44

2K+ Views

When it is required to find the Fibonacci sequence using the method of recursion, a method named ‘fibonacci_recursion’ is defined, that takes a value as parameter. It is called again and again by reducing the size of the input.Below is a demonstration of the same:Exampledef fibonacci_recursion(my_val): if ... Read More

Python – Inverse Dictionary Values List

AmitDiwan

AmitDiwan

Updated on 07-Sep-2021 10:40:32

347 Views

When it is required to inverse the dictionary values to a list, a simple iteration and ‘append’ method is used.Below is a demonstration of the same −from collections import defaultdict my_dict = {13: [12, 23], 22: [31], 34: [21], 44: [52, 31]} print("The dictionary is :") print(my_dict) my_result = defaultdict(list) ... Read More

Python – Sort String list by K character frequency

AmitDiwan

AmitDiwan

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

357 Views

When it is required to sort a list of strings based on the ‘K’ number of character frequency, the ‘sorted’ method, and the lambda function is used.ExampleBelow is a demonstration of the same −my_list = ['Hi', 'Will', 'Jack', 'Python', 'Bill', 'Mills', 'goodwill'] print("The list is : " ) print(my_list) my_list.sort() ... Read More

Pandas GroupBy – Count the occurrences of each combination

AmitDiwan

AmitDiwan

Updated on 07-Sep-2021 09:14:11

2K+ Views

To groupby columns and count the occurrences of each combination in Pandas, we use the DataFrame.groupby() with size(). The groupby() method separates the DataFrame into groups.At first, let us import the pandas library with an alias pd −import pandas as pdInitialize the data of lists −# initializing the data mylist ... Read More

Python Program to extracts elements from a list with digits in increasing order

AmitDiwan

AmitDiwan

Updated on 06-Sep-2021 09:15:38

150 Views

When it is required to extracts elements from a list with digits in increasing order, a simple iteration, a flag value and the ‘str’ method is used.Below is a demonstration of the same −Example Live Demomy_list = [4578, 7327, 113, 3467, 1858] print("The list is :") print(my_list) my_result = ... Read More

Python – Dual Tuple Alternate summation

AmitDiwan

AmitDiwan

Updated on 06-Sep-2021 09:13:39

176 Views

When it is required to perform dual tuple alternate summation, a simple iteration and the modulus operator are used.Below is a demonstration of the same −Example Live Demomy_list = [(24, 11), (45, 66), (53, 52), (77, 51), (31, 10)] print("The list is :") print(my_list) my_result = 0 for index ... Read More

Python – Extract Rear K digits from Numbers

AmitDiwan

AmitDiwan

Updated on 06-Sep-2021 08:56:24

215 Views

When it is required to extract rear K digits from numbers, a simple list comprehension, the modulo operator and the ‘**’ operator are used.Below is a demonstration of the same −Example Live Demomy_list = [51645, 24567, 36743, 89452, 2122] print("The list is :") print(my_list) K = 3 print("The value ... Read More

Python – Combine list with other list elements

AmitDiwan

AmitDiwan

Updated on 06-Sep-2021 08:54:58

205 Views

When it is required to combine list with other list elements, a simple iteration and ‘append’ method is used.Below is a demonstration of the same −Example Live Demomy_list_1 = [12, 14, 25, 36, 15] print("The first list is :") print(my_list_1) my_list_2 = [23, 15, 47, 12, 25] print("The ... Read More

Advertisements