Tag: Lists
Python : Join / Merge lists ( two or more)
In this article we will discuss different ways to Merge / Join two or more lists in python. Table of Contents Join / Merge two lists in python using + operator. Join / Merge two lists in python using list.extend(). Join / Merge two lists in python using unpacking. Join / Merge two lists in …
np.array() : Create Numpy Array from list, tuple or list of lists in Python
In this article we will discuss how to create a Numpy Array from a sequence like list or tuple etc. Also, how to create a 2D numpy Numpy Array from nested sequence like lists of lists. np.array() – Creating 1D / 2D Numpy Arrays from lists & tuples in Python To install the python’s numpy module …
np.array() : Create Numpy Array from list, tuple or list of lists in PythonRead More
Python : Get number of elements in a list, lists of lists or nested list
In this article we will discuss different ways to count number of elements in a flat list, lists of lists or nested lists. Count elements in a flat list Suppose we have a list i.e. Advertisements # List of strings listOfElems = [‘Hello’, ‘Ok’, ‘is’, ‘Ok’, ‘test’, ‘this’, ‘is’, ‘a’, ‘test’] To count the elements …
Python : Get number of elements in a list, lists of lists or nested listRead More
Python : Convert list of lists or nested list to flat list
In this article we will discuss different ways to convert a list of lists or nested lists to a single flat list. Convert a list of lists to a flat list Suppose we have a list of lists i.e. Advertisements # List of list listOfList = [ [1, 2, 3, 4, 5], [11, 22, 33, …
Python : Convert list of lists or nested list to flat listRead More
Pandas : Convert a DataFrame into a list of rows or columns in python | (list of lists)
In this article, we will discuss how to convert a dataframe into a list of lists, by converting either each row or column into a list and create a python list of lists from them. First of all, create a dataframe, Advertisements import pandas as pd # List of Tuples students = [(‘jack’, 34, ‘Sydney’, …
Pandas : Convert a DataFrame into a list of rows or columns in python | (list of lists)Read More
Python: Read CSV into a list of lists or tuples or dictionaries | Import csv to list
In this article we will discuss how to import a CSV into list. This list can be a list of lists, list of tuples or list of dictionaries. We will also use pandas module and cover scenarios for importing CSV contents to list with or without headers. Suppose we have a CSV file ‘students.csv’ and …
Python: Read CSV into a list of lists or tuples or dictionaries | Import csv to listRead More
How to create and initialize a list of lists in python?
Creating a list of lists in python is a little tricky. In this article, we will discuss 4 different ways to create and initialize list of lists. Wrong way to create & initialize a list of lists in python Let’s start from basic, quickest way to create and initialize a normal list with same values …
How to create and initialize a list of lists in python?Read More
Python: check if two lists are equal or not ( covers both Ordered & Unordered lists)
In this article we will discuss 8 different ways to check if two lists are equal or not. Suppose we have two lists and we want to check if both the lists are equal or not. There can be two meanings of 2 equality here, Advertisements Both lists must contain the same unique elements and …
Python: check if two lists are equal or not ( covers both Ordered & Unordered lists)Read More
Compare & get differences between two lists in Python
In this article we will discuss 10 different ways to compare two lists and get their differences i.e. elements which are present in one list but not in another. Suppose we have two lists, Advertisements first_list = [10, 11, 12, 13, 14, 16, 15] sec_list = [10, 11, 12, 18, 19, 16] Now there might …
Compare & get differences between two lists in PythonRead More
Convert 2D NumPy array to list of lists in python
In this article, we will learn how to convert 2D Numpy Array to a nested list i.e. list of lists. Convert 2D Numpy Array to list of lists using tolist() In Python’s numpy module, the ndarray class provides a member function tolist(), which returns a list containing the copy of elements in the numpy array. …