Tag: list

60 votes
27 answers
371 views
How do I check if a list is empty?

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
678 views
Finding the index of an item in a list

Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index (1) in Python?

avatar
Chelsea
0 1 0 9
asked 07 September, 2021
52 votes
30 answers
579 views
Understanding slice notation

I need a good explanation (references are a plus) on Python's slice notation. To me, this notation need

avatar
Arline
0 1 0 9
asked 07 September, 2021
62 votes
20 answers
900 views
How to make a flat list out of a list of lists

Is there a shortcut to make a simple list out of a list of lists in Python? I can do it in a for loop, but is

avatar
Karolyn
0 1 0 9
asked 07 September, 2021
52 votes
23 answers
2.7K views
Accessing the index in 'for' loops?

How do I access the index in a for loop like the following? ints = [8, 23, 45, 12, 78] for i in ints: pri

avatar
Hildegard
0 1 0 9
asked 07 September, 2021
50 votes
30 answers
2.9K views
Array versus linked-list

Why would someone want to use a linked-list over an array? Coding a linked-list is, no doubt, a bit more work

avatar
Chaya
0 1 0 9
asked 07 September, 2021
57 votes
10 answers
1.9K views
Python Sets vs Lists

In Python, which data structure is more efficient/speedy? Assuming that order is not important to me and I wou

avatar
Trudy
0 1 0 9
asked 07 September, 2021
54 votes
7 answers
1.9K views
Skip List vs. Binary Search Tree

I recently came across the data structure known as a skip list. It seems to have very similar behavior to a bi

avatar
Jeff
0 1 0 9
asked 07 September, 2021
56 votes
18 answers
1.7K views
How to convert List to Map?

Recently I have conversation with a colleague about what would be the optimal way to convert List to Map in Ja

avatar
Benton
0 1 0 9
asked 07 September, 2021
65 votes
12 answers
1.3K views
In Python, when to use a Dictionary, List or Set?

When should I use a dictionary, list or set? Are there scenarios that are more suited for each data type?

avatar
Ali
0 1 0 9
asked 07 September, 2021
57 votes
13 answers
1.7K views
How to Correctly Use Lists in R?

Brief background: Many (most?) contemporary programming languages in widespread use have at least a handful of

avatar
Keith
0 1 0 9
asked 07 September, 2021
58 votes
16 answers
2.9K views
When should I use a List vs a LinkedList

When is it better to use a List vs a LinkedList?

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
56 votes
26 answers
1.7K views
How to detect a loop in a linked list?

Say you have a linked list structure in Java. It's made up of Nodes: class Node { Node next; //

avatar
Shantay
0 1 0 9
asked 07 September, 2021
60 votes
18 answers
1K views
How do I sort a list of dictionaries by a value of the dictionary?

I have a list of dictionaries and want each item to be sorted by a specific value. Take into consideration the

avatar
Nereida
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
2.2K views
Initialization of an ArrayList in one line

I wanted to create a list of options for testing purposes. At first, I did this: ArrayList<String> plac

avatar
Dorian
0 1 0 9
asked 07 September, 2021
54 votes
30 answers
918 views
When to use LinkedList over ArrayList in Java?

I've always been one to simply use: List<String> names = new ArrayList<>(); I use the inte

avatar
Sena
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
339 views
Create ArrayList from array

I have an array that is initialized like: Element[] array = {new Element(1), new Element(2), new Element(3)};

avatar
Margo
0 1 0 9
asked 07 September, 2021