Pradeep Elance has Published 417 Articles

Concatenate two lists element-wise in Python

Pradeep Elance

Pradeep Elance

Updated on 20-May-2020 10:28:39

1K+ Views

Pyhton has great data manipulation features. In this article we will see how to combine the elements from two lists in the same order as they are present in the lists.With zipThe zip function can take in the two lists as parameters and concatenate them. We design a for loop ... Read More

Combining values from dictionary of list in Python

Pradeep Elance

Pradeep Elance

Updated on 20-May-2020 10:26:12

565 Views

Let’s say we have a python dictionary which has lists as it values in the key value pairs. We need to create a list which will represent all possible combinations of the keys and values from the given lists.With sorted and productThe product function from itertools can be used to ... Read More

Combining two sorted lists in Python

Pradeep Elance

Pradeep Elance

Updated on 20-May-2020 10:21:37

346 Views

Lists are one of the most extensively used python data structures. In this article we will see how to combine the elements of two lists and produce the final output in a sorted manner.With + and sortedThe + operator can join the elements of two lists into one. Then we ... Read More

Combining tuples in list of tuples in Python

Pradeep Elance

Pradeep Elance

Updated on 20-May-2020 10:20:36

587 Views

For data analysis, we sometimes take a combination of data structures available in python. A list can contain tuples as its elements. In this article we will see how we can combine each element of a tuple with another given element and produce a list tuple combination.With for loopIn the ... Read More

Checking triangular inequality on list of lists in Python

Pradeep Elance

Pradeep Elance

Updated on 20-May-2020 10:15:50

327 Views

The sum of two sides of a triangle is always greater than the third side. This is called triangle inequality. Python list of lists we will identify those sublists where the triangle inequality holds good.With for and >We will first get all the sublists sorted. Then for each sublist we ... Read More

Checking if starting digits are similar in list in Python

Pradeep Elance

Pradeep Elance

Updated on 20-May-2020 10:09:50

356 Views

Sometimes in a given Python list we may be interested only in the first digit of each element in the list. In this article we will check if the first digit of all the elements in a list are same or not.With set and mapSet in Python does not allow ... Read More

Check whether a string is valid JSON or not in Python

Pradeep Elance

Pradeep Elance

Updated on 20-May-2020 10:04:16

1K+ Views

JSON is a type of text format use to exchange data easily between various computer programs. It has a specific format which Python can validate. In this article we will consider a string and using JSON module we will validate if the string represents a valid JSON format or not.Creating ... Read More

Find common elements in list of lists in Python

Pradeep Elance

Pradeep Elance

Updated on 13-May-2020 14:54:18

2K+ Views

It is possible to have a list whose inner elements are also lists. In such cases we may come across a need when we have to find out the common elements among these inner lists. In this article we will find out the approaches to achieve this.With map and intersectionIntersection ... Read More

Convert list into list of lists in Python

Pradeep Elance

Pradeep Elance

Updated on 13-May-2020 14:52:01

3K+ Views

During data analysis we face scenarios to convert every element of a list into a sublist. So in this article we will need to take a normal list as an input and convert into a list of lists where each element becomes a sublist.Using for loopThis is a very straight ... Read More

Convert dictionary to list of tuples in Python

Pradeep Elance

Pradeep Elance

Updated on 13-May-2020 14:49:30

854 Views

Converting from one collection type to another is very common in python. Depending the data processing needs we may have to convert the key value pairs present in a dictionary to pairs representing tuples in a list. In this article we will see the approaches to achieve this.With inThis is ... Read More

Advertisements