# List

## Get sublist from List based on indices in Python

This tutorial will discuss about unique ways to get sublist from list based on indices in Python. Table Of Contents Method 1: Using List Comprehension Method 2: Using operator.itemgetter() Summary Method 1: Using List Comprehension Iterate over list of index positions using a List comprehension, and for each index position, select the element at that …

## Get Sublist from List based on condition in Python

This tutorial will discuss about unique ways to get a sublist from a list based on certain conditions in Python. Table Of Contents Method 1: Using filter() method Example 1: Get a sublist containing only odd numbers from list. Example 2: Get a sublist containing numbers between 70 to 80 from the list. Method 2: …

## Get first character of each string in List in Python

This tutorial will discuss about unique ways to get first character of each string in list in Python. Table Of Contents Method 1: Using map() method Method 2: Using List comprehension and isinstance() Method 3: Using for-loop Summary Method 1: Using map() method In this solution, we are assuming that your list has string elements …

## Get Last element in List that matches condition in Python

This tutorial will discuss about unique ways to get last element of a List, that matches a given condition in Python. Table Of Contents Introduction Method 1: Using next() method Method 2: Using for-loop Method 3: Using any() method Summary Introduction Suppose we have a list of numbers, and we want to get the last …

## Get first element in List that matches condition in Python

This tutorial will discuss about unique ways to get first element in list that matches condition in Python. Table Of Contents Introduction Method 1: Using next() method Method 2: Using for-loop Method 3: Using any() method Summary Introduction We have a list of numbers, and we want to get the first odd number from that …

## Convert a comma-separated string to a List in Python

This tutorial will discuss about unique ways to convert a comma-separated string to a list in Python. Table Of Contents Split the string by comma Split the string by comma and strip extra spaces Split the string by comma and handle empty string Summary Split the string by comma String class in python has a …

## Convert comma-separated string to List of Integers in Python

This tutorial will discuss about unique ways to convert comma-separated string to list of integers in Python. Table Of Contents Quick Solution: Better Solution Summary Quick Solution: First split the string using a comma as a delimeter i.e. It will split the string into multiple strings by using a comma as a delimeter. It returns …

## Convert List of booleans to List of integers in Python

This tutorial will discuss about unique ways to convert list of booleans to list of integers in Python. Table Of Contents Introduction Method 1: Using List Comprehension Method 2: Using NumPy Array Summary Introduction Suppose we have a list of booleans containing only False and True values. Like this, Now we want to convert this …

## Convert List of 1s and 0s to a List of booleans in Python

This tutorial will discuss about unique ways to convert list of 1s and 0s to a list of booleans in Python. Table Of Contents Introduction Method 1: Using List Comprehension Method 2: Using NumPy Array Summary Introduction Suppose we have a list of integers containing only 1s and 0s. Like this, Now we want to …

## Convert a list to a comma-separated string in Python

This tutorial will discuss about unique ways to convert a list to a comma-separated string in Python. Table Of Contents Convert list of strings to comma-separated string Convert list with some non string elements to comma-separated string Summary Convert list of strings to comma-separated string If you know that your list has only strings, then …

Scroll to Top