Check if a List is sorted in Python

In the previous article, we saw how we can obtain a count of all the distinct elements of a list. Now we will look at how we can implement a program to Check if a List is sorted in Python. We need to check if the list is in non-decreasing order, as in every element … Read more

Program to return Smaller list Elements in Python

In the previous article we discussed handling of slicing on tuples, strings and lists in python. Now let us explore how we can handle a problem related to list concept. We need to write a function that takes a list as input, also takes a value for ‘x’ as input. The function should return all … Read more

Program to separate Even and Odd List Elements

In the previous article we explored how we could write a function to return the smaller elements from a list. Now we will apply similar logic to write a function to separate even and odd list elements. We are given a list, we need to write a function that takes the list as argument and … Read more

Count Distinct Elements in a List in Python

In the previous article we discussed how to to obtain the average/mean of a given list, now we will see how we can write a program to Count Distinct Elements in a List in Python. Suppose we are given a list L=[10,20,10,30,30,20], we see that there some of the elements occur multiple times within the … Read more

Average or Mean of a List in Python

In the previous article, we explored the concept of Comprehensions in Python. Now let us look at how we can obtain the average or mean of a list in Python. Let us look at an example, we have a list l1: l1=[10,20,30,40] There are four elements in the list, and the average can be obtained … Read more

Slicing in Python (Tuples, Strings, Lists)

In the previous article we explored the conversions of Binary to Decimal. Now we will explore the concept of slicing, slicing in Python is the process of extracting a specific sub portion of an iterable data structure, according to the user-specified criteria. Very often, it is necessary to get not one certain element, but a … Read more

Comprehensions in Python

In the previous article we saw how we could obtain the even and odd elements of a list, separately and return them. Now we will explore the concept of Comprehensions in Python with regards to lists, sets and dictionaries. What is List Comprehension? List Comprehension provides us a shortcut to create a new list from … Read more