How-to articles, tricks, and solutions about LIST

How do I concatenate two lists in Python?

There are a few ways to concatenate lists in Python.

How do I convert a Map to List in Java?

You can use the entrySet() method of the Map interface to get a Set view of the mappings contained in the map, and then create a List from this set using the new

How do I count the occurrences of a list item?

There are a few ways you can count the occurrences of a list item in Python:

How do I create a list with numbers between two values?

Here is an example of how you might create a list of numbers between two values in python:

How do I find the duplicates in a list and create another list with them?

In Python, one way to find duplicates in a list and create another list with them is to use a for loop and an if statement.

How do I get the last element of a list?

To get the last element of a list, you can use negative indexing.

How do I get the number of elements in a list (length of a list) in Python?

To get the number of elements in a list in Python, you can use the len() function.

How do I iterate through two lists in parallel?

You can use the zip() function to iterate through two lists in parallel.

How do I join two lists in Java?

There are several ways to join two lists in Java. Here are a few options:

How do I make a flat list out of a list of lists?

To create a flat list out of a list of lists, you can use the itertools.chain function from the itertools module in the Python standard library.

How do I remove repeated elements from ArrayList?

To remove repeated elements from an ArrayList in Java, you can use the removeAll method and pass it a Collection containing the elements to be removed.

How do I remove the first item from a list?

You can use the list method pop(index) to remove the first item in a list.

How do I reverse a list or loop over it backwards?

There are a few ways to reverse a list in Python, depending on what you want to do with the reversed list.

How do I sort a list of dictionaries by a value of the dictionary?

To sort a list of dictionaries by a value of the dictionary, you can use the sorted() function and specify the key parameter to be a lambda function that returns the value you want to sort by.

How do I split a list into equally-sized chunks?

Here is a function that takes a list and an integer n and splits the list into n equally sized chunks:

How do I split a string into a list of characters?

In Python, you can use the built-in list() function to convert a string into a list of characters.

How do I split a string into a list of words?

Here is an example of how to split a string into a list of words in Python:

How to Add Indentation for the Second Line of an Ordered List

On this page, you can find out how it is possible to add an indentation for the second line of ordered lists. Read our snippet and find a solution to the problem.

How to check if a string is a substring of items in a list of strings

You can use a for loop to iterate through the list of strings, and then use the in keyword to check if the string is a substring of the current item in the list.

How to concatenate (join) items in a list to a single string

You can use the join() method to concatenate (join) items in a list to a single string in Python.

How to Control the Space Between Bullets and <li> Elements

In this snippet, you can find out how to control the space between bullets and <li> elements. You can use the HTML <span> element and the CSS left property.

How to convert a Collection to List?

In Java, you can convert a Collection (such as Set, Queue, etc.) to a List using the following methods:

How to convert array to list in Java

To convert an array to a list in Java, you can use the Arrays.asList() method. This method returns a fixed-size list backed by the specified array. Here's an example: