AmitDiwan has Published 10744 Articles

Python – Find the frequency of numbers greater than each element in a list

AmitDiwan

AmitDiwan

Updated on 04-Sep-2021 11:24:15

231 Views

When it is required to find the frequency of numbers greater than each element in a list, a list comprehension and the ‘sum’ method is used.Below is a demonstration of the same −Example Live Demomy_list = [24, 13, 72, 22, 12, 47] print("The list is :") print(my_list) my_result = ... Read More

Python program to convert elements in a list of Tuples to Float

AmitDiwan

AmitDiwan

Updated on 04-Sep-2021 11:22:54

347 Views

When it is required to convert elements in a list of tuples to float values, the ‘isalpha’ method, the ‘float’ method, and a simple iteration is used.Below is a demonstration of the same −Example Live Demomy_list = [("31", "py"), ("22", "226.65"), ("18.12", "17"), ("pyt", "12")] print("The list is :") print(my_list) ... Read More

Python Program to test whether the length of rows are in increasing order

AmitDiwan

AmitDiwan

Updated on 04-Sep-2021 11:21:21

122 Views

When it is required to test whether the length of rows are in increasing order, a simple iteration and a Boolean value is used.Below is a demonstration of the same −Example Live Demomy_list = [[55], [12, 17], [25, 32, 24], [58, 36, 57, 19, 14]] print("The list is :") print(my_list) ... Read More

Python program to find the sum of all even and odd digits of an integer list

AmitDiwan

AmitDiwan

Updated on 04-Sep-2021 11:19:22

1K+ Views

When it is required to find the sum of all even and odd digits of an integer list, a simple iteration and the ‘modulus’ operator are used.Below is a demonstration of the same −Example Live Demomy_list = [369, 793, 2848, 4314, 57467] print("The list is :") print(my_list) sum_odd = ... Read More

Python – Test for Word construction from character list

AmitDiwan

AmitDiwan

Updated on 04-Sep-2021 11:18:00

193 Views

When it is required to test for word construction from character list, the ‘all’ operator and the ‘count’ method is used.Below is a demonstration of the same −Example Live Demomy_list = ['p', 'p', 'y', 't', 'h', 'p', 'p', 'y', 'n', 'y', 'y', 't'] print("The list is :") print(my_list) key ... Read More

Python – Get Every Element from a String List except for a specified letter

AmitDiwan

AmitDiwan

Updated on 04-Sep-2021 11:16:20

411 Views

When it is required to get every element from a list of strings except a specified letter, a list comprehension and the ‘append’ method is used.Below is a demonstration of the same −Example Live Demomy_list = ["hi", "is", "great", "pyn", "pyt"] print("The list is :") print(my_list) my_key = 'n' ... Read More

Python - Print rows from the matrix that have same element at a given index

AmitDiwan

AmitDiwan

Updated on 04-Sep-2021 11:15:06

301 Views

When it is required to print the rows from the matrix that have the same element at the given index, a list comprehension and the ‘all’ operator is used.Below is a demonstration of the same −Example Live Demomy_list = [[7745, 6755, 87, 978], [727, 927, 845], [192, 997, 49], [98, 74, ... Read More

Python Program – Print the count of either peaks or valleys from a list

AmitDiwan

AmitDiwan

Updated on 04-Sep-2021 11:13:43

308 Views

When it is required to print the count of either peaks or valleys from a list, a simple iteration and a specific condition is placed.Below is a demonstration of the same −Example Live Demomy_list = [11, 12, 24, 12, 36, 17, 28, 63] print("The list is :") print(my_list) my_result ... Read More

Python – Consecutive Division in List

AmitDiwan

AmitDiwan

Updated on 04-Sep-2021 11:11:48

227 Views

When it is required to find the consecutive division in a list, a method is defined that iterates over the elements of the list and uses the ‘/’ operator to determine the result.Below is a demonstration of the same −Example Live Demodef consec_division(my_list):    my_result = my_list[0]    for idx ... Read More

Python – Filter immutable rows representing Dictionary Keys from Matrix

AmitDiwan

AmitDiwan

Updated on 04-Sep-2021 11:10:11

153 Views

When it is required to filter immutable rows representing dictionary keys from a matrix, a list comprehension and the ‘isinstance’ method can be used.Below is a demonstration of the same −Example Live Demomy_list = [[24, 15, [32, 33, 12]], ["pyt", 8, (14, 54)], [{15:24}, 13, "fun"], [True, "cool"]] print("The list ... Read More

Advertisements