Pradeep Elance has Published 445 Articles

Find the list elements starting with specific letter in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 11:46:22

2K+ Views

In this article we will find all those elements from a list which start with specific letter.With index and lowerWe use the lower function so that the test later can match with the first letter of the the elements in the list irrespective of the case. Then we use the ... Read More

Find most frequent element in a list in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 11:44:36

7K+ Views

In this article we will see how to find the element which is most common in a given list. In other words, the element with highest frequency.With max and countWe apply why the set function to get the unique elements of the list and then keep account of each of ... Read More

Find most common element in a 2D list in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 11:42:24

523 Views

A 2D list has list as its element. In other words it is a list of lists. In this article we are required to find the element which is most common among all the lists inside a list.With max and countWe design a follow with a in condition to check ... Read More

Find maximum value in each sublist in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 11:40:56

289 Views

We are given a list of lists. In the inner lists or sublists we are required to find the maximum value in each.With max and inWe design a for loop with in condition and apply the max function to get the maximum value in each of the sublist.Example Live DemoAlist = ... Read More

Count tuples occurrence in list of tuples in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 11:39:00

397 Views

A list is made up of tuples as its element. In this article we will count the number of unique tuples present in the list.With defaultdictWe treat the given list as a defaultdict data container and count the elements in it using the in condition.Example Live Demoimport collections Alist = [[('Mon', ... Read More

Count the sublists containing given element in a list in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 11:37:17

331 Views

The elements in a given list can also be present as another string in another variable. In this article we'll see how many times a given stream is present in a given list.With range and lenWe use the range and len function to keep track of the length of the ... Read More

Count the Number of matching characters in a pair of string in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 11:34:46

713 Views

We are given two strings. We need to find the count it of the characters in the first string which are also present in a second string.With setThe set function gives us unique values all the elements in a string. We also use the the & operator which finds the ... Read More

Count of elements matching particular condition in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 11:32:17

416 Views

In this article we will see how to get some selected elements out of a Python list. So we need to design some condition and only the elements satisfying that condition should be picked and their count to be printed.Wit in and sumIn this approach we use in condition to ... Read More

Count occurrences of an element in a list in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 11:31:13

468 Views

In this article we are given a list and a string. We are required to find how many times the given string is present as an element in the list.With CounterThe counter function from collections module will give us the count of each element present in the list. From the ... Read More

Count occurrences of a character in string in Python

Pradeep Elance

Pradeep Elance

Updated on 04-Jun-2020 11:28:28

626 Views

We are given a string and a character. We want to find out how many times the given character is repeated in a given string.With range and lenWe design a for loop to match the character with every character present in the string which are accessed using index. The range ... Read More

Advertisements