Most voted "list" questions
A list is an abstract type of data that represents a sequence of values, in which the same value can occur more than once. The main ways to implement a list is through an array (array, vector or one-dimensional matrix) or a chained list.
Learn more…1,022 questions
Sort by count of
-
6
votes3
answers11827
viewsUse list as dictionary value using Python append() method
I have some python dictionary, and I want to assign a list as a value for each dictionary key, but I need to use the append() method to add elements, but after adding the elements to the list, the…
-
6
votes4
answers3435
views -
6
votes2
answers8444
viewsPass generic list as parameter
You can pass a generic list by parameter? Ex: I have one List<Pessoa> and a List<object>. and I have my method: public void FaçaAlgo(List<T> lista) { } How can I make my method…
-
6
votes1
answer190
viewsDifference between "list(range(1, 10))" and "range(1, 10)"?
I asked that question here How to format all elements of a list in Python?. In one of the answers, @Ciganomorrisonmendez, put the following excerpt: list(range(1, 10)) But every time I used the…
-
6
votes2
answers938
viewsHow to join lists in c#?
I have two classes: public class Produto { public int ProCodigo { get; set; } public string ProNome { get; set; } public int DepCodigo { get; set; } public virtual Departamento Departamento { get;…
-
6
votes3
answers1779
viewsHow not to repeat values in a Python list?
If I create two lists, and then add the two, I create a third that owns all the items of the previous two: >>>a = [1, 2, 3] >>>b = [3, 4, 5] >>>c = a + b >>>print…
-
6
votes1
answer310
viewsSearch list elements with partial strings
I have a List<string> who receives the phone number of all the contacts on the phone, until there is no problem, but I want to perform some operations with the elements of that list, but I am…
-
6
votes2
answers191
viewsDoes the List<T> Method. Foreach exist?
I’m trying to implement the example of this page, but VS2015 (.NET 4.5) says the method ForEach() there is no class Program { static void Main() { List<String> names = new…
-
6
votes3
answers269
viewsI need to sort a list in order that seems unusual
I have a query and want to sort this query by the attribute code. I did it as follows: consulta.OrderBy(c => c.Codigo); Result obtained: 1.01 1.A 14.04 14.11 22.01 3.04 30.01 4.01 40.02 Expected…
-
6
votes1
answer214
viewsError while printing static list
How do I print my static list? #include <stdio.h> #include <stdlib.h> #define MAX 3 struct alunos { int matricula; char nome[30]; float nota1, nota2; }; typedef struct lista { int quant;…
-
6
votes2
answers99
viewsDoubt about List that does not return the result
I have this method in Java, which queries in the database and returns me a list of students. The method is searching in the BD, but does not return the data correctly... public static…
-
6
votes2
answers272
viewsIn R, what is the best way to select sets of internal lists within a list of lists?
I have a list of lists like the one below: lista <- list(num = list(1:10, 11:20, 21:30), chr = list(letters[1:13], letters[14:26], LETTERS[1:13])) I’d like to turn it into a data.frame, but for…
-
6
votes1
answer1909
views -
6
votes3
answers390
viewsIs it possible to place objects in an Arraylist as soon as instantiated?
Doubt applies not only in one ArrayList, but in any kind of List. It is possible to add objects to ArrayList soon after we instantiate it, and without having to use the method add()? As can be done…
-
6
votes3
answers1428
viewsHow to define the comparison of equality between two objects present in an Arraylist?
How can I define the equality comparison behavior between two objects whose class is defined by me that are stored in an Arraylist object? Java nomecor. public class NomeCor { private String nome;…
-
6
votes4
answers1049
viewsString list + . Split()
The command string.Split() separates a string in a array of the kind string[]. How to use the string.Split() to separate strings in a list List < string>?…
-
6
votes1
answer591
viewsAdd list values with different sizes
I have two lists with varying numbers and sizes. For example: array 1 ['1', '142', '33', '33', '9', '2'] array 2 ['1', '12', '7', '-2', '39', '11', '31', '49', '50', '1'] How do I make a loop to add…
-
6
votes2
answers1649
viewsWhat is the underscore (or underline _ ) for in the repeating structure?
What this _ ago? Why it is being used in the code snippet below? print('3 numeros') data = [] for _ in range(3): data.append(input()) numbers = list(map(int, data)) print(numbers)…
-
6
votes1
answer272
viewsSort list by string resemblance
I have a list of string: AAA BBB CCC ABB ABC ACC ACD The user will type what he is looking for, would like to take to the first positions, the most similar. Example: String: A Upshot: AAA ABB ABC…
-
6
votes1
answer247
viewsSize of a list list using list.Capacity
Creating a list of lists: List<List<int>> myList = new List<List<int>>(); I add elements in myList with 1 element: myList.Add(1); When I do debug.writeLine(myList.capacity)…
-
6
votes2
answers236
viewsRemove unwanted characters from a List<string> without going through the list
Be the following excerpt a Windows Forms application. List<string> lista_strings = new List<string>(); for (int i = 0; i < 2000; i++) { lista_strings.Add("TST1234"); //preenchendo a…
-
6
votes5
answers1031
viewsCheck that all items in the list are equal
I have a list of times containing the values of times of several cars and I would like to know how do I know if all these values are equal I thought to compare each value with its later, ie compare…
-
5
votes3
answers10914
viewsHow to remove the first element from a list in python?
I have the following code: On the command line > teste.py primeiro segundo In the script teste.py: import sys print(sys.argv) And I have the following return: ['c:\\teste.py', 'primeiro',…
-
5
votes1
answer1589
viewsDoubt between Any and All in a lambda expression on a list
On a list, I have 12 records (hypothetical) and there is a field called ValorCampoFlag, where this field receives 1 or null, for example. If I do a validation on it and the result if there is at…
-
5
votes5
answers25936
viewsHow to pass a list of values to a Stored Procedure?
I’m creating a stored Procedure in SQL Server 2008 R2 and would like to pass a list of values per parameter, for example: Table produto ---------------- | id | nome | | 1 | maçã | | 2 | pera | | 3 |…
-
5
votes2
answers518
viewsData Structure - C Double Chained List
I’m doing an activity proposed by a teacher, who asks to remove an element from the end of a double chained list. Except the function I set up to solve the problem is locking the program. In the…
-
5
votes3
answers1630
viewsMount a single string with multiple strings from a Java Arraylist
How can I take several Strings of an Arraylist in a simplified way and join in only one String type variable? I’m new to Java and I’m having difficulty completing this change in a simplified way,…
-
5
votes4
answers13756
viewsSort List in java
I have a List<Pessoa> where the attributes of the object are: Name, age, address, etc. I have a screen where I insert people in this list and I submit a report, I would like to display this…
-
5
votes3
answers396
viewsDoubt: dynamic list chained inside another, in C
I’m having a huge difficulty to be able to create a dynamically chained list within another using data structure and manipulation, because I haven’t found anything that exemplifies how to create a…
-
5
votes2
answers1685
viewsHow to format all elements of a list in Python?
In php, when I want to generate a array formatted, I use the function array_map. Thus: $numeros = range(1, 10); array_map(function ($value) { return sprintf('%04', $value); }, $numeros); Returns:…
-
5
votes1
answer1046
viewsHow to take data from a list only when there are two equal codes
Currently I can only take different data from two lists, for example: Lista X Código 1 Código 2 Lista z: Código 1 Código 3 I can only get the code 2 and 3. Now arose the need to take the same data,…
-
5
votes1
answer90
viewsWhat’s wrong with my chained list?
I implemented a chained list but when I enter 2 items, I remove the last one and add it again, for some reason it says that the value is null. public class ListaDinamica<T> { private class…
-
5
votes1
answer10433
viewsWhat is the difference between Sorted() and . Sort()?
Why the function sorted() is considered more direct than the method .sort() used in lists with tuples?
-
5
votes4
answers2109
views"Filter" equal records into a list by adding their quantitative
namespace ConsoleApplication10 { class Program { static void Main(string[] args) { List<Teste> lstTeste = new List<Teste> { new Teste {Codigo = 1, Quantidade = 10}, new Teste {Codigo =…
-
5
votes1
answer219
viewsHow to simplify code with Foreach List?
How to use the ForEach() of List in the implementation below using System.Collections.Generic; public class Program { public static void Main() { List<Pessoa> pessoas = new…
-
5
votes2
answers1642
viewsHow do you convert an Enum guy into a list?
Is there any way to convert a Enum in List? public enum TiposHospedagem { Casa = 1, Hotel = 2, Pousada = 3, CasaCampo = 4 } I’m trying to run the enum and add to the list, but the foreach does not…
-
5
votes2
answers101
viewsHow to get an item from a list randomly?
Suppose I have the following list: frutas = ['abacate', 'mamão', 'laranja', 'uva', 'pêra'] I need to capture one of these elements from list randomly. How would I do it in Python?…
-
5
votes1
answer115
viewsOperation with very large size lists
I have a code that calculates the area of the intersection between two polygons and for that I use lists to store the coordinates of the vertices of the polygons, however there are many polygons and…
-
5
votes1
answer2775
viewsLoad Combobox from a List<>
I’m trying to load items into one ComboBox from a List<>, worked out however, later I would need to get the code referring to the selected item, but it is not working. The code to load the…
-
5
votes1
answer944
viewsHow to switch between the next element and the previous element of a Listiterator with just one click?
I have a list of words stored in my variable listaPalavra already initialized with values, of type ArrayList<T>: listaPalavra.add("Palavra 1"); listaPalavra.add("Palavra 2");…
-
5
votes1
answer192
viewsBug when reordering React component list
I have a component that loads a list of components <ComponenteReordenavel> which is reordered according to the user’s taste. The bug happens when I modify the style of that component and…
-
5
votes1
answer4065
viewsPython, clone the lists
Be the code below: def modif1(lista): lista = [4,5,6] lista = [1,2,3] modif1(lista) print(lista) #resultado: [1,2,3] def modif2(lista): lista[0] = 4 lista[1] = 5 lista[2] = 6 lista = [1,2,3]…
-
5
votes2
answers2728
viewsHow to separate only the first word of each string from a list?
Given that list : nomes = [ " Paulo Ricardo " , " Fabio Junior " , " Roberto Carlos " ] How do I create a new list, separating the last name from the last name and only adding the last name without…
-
5
votes4
answers283
viewsCreate list with more than one element as if it were multidimensional
I need to receive these pairs of data from the bank, and I’m thinking of a way to bring the values without creating an object, because I think it’s unnecessary in this case. It is possible to create…
-
5
votes2
answers330
viewsDifference between Find, Exists and Contains of the List<T> class
I’m working with the class List<T>, so I came across some research methods, if I may call it: Find; Exists; Contains; I was in doubt of what the difference between them, so I searched on the…
-
5
votes4
answers5739
viewsHow to separate the letters of a string that are inserted into a list and place them in an array?
I have a list with the word "test", arranged in such a way: ['teste','teste','teste','teste','teste'] I would like to turn this list into a matrix, in which the letters are separated from each…
-
5
votes3
answers2851
viewsJava repeated letter counter
I made a method to count the repeated letters that are stored and ordered alphabetically within a list. The method is counting right but the bug is at the time of printing, it prints the letter and…
-
5
votes3
answers195
viewsList without negative number
The exercise is as follows: a program that reads the values and separates them into a list of pairs or odd numbers. The count only stops when a negative number comes (which should not be on the…
-
5
votes3
answers139
viewsLists within lists: Even when sliced, there is connection between lists
I’m studying lists and there’s a behavior I don’t understand. I know that when I equate one list with another, a connection between them is created. And that when I slice a list, I create a copy of…
-
5
votes1
answer85
viewsWhat are columns-lists of a data.frame?
The tidyverse stimulates the use of columns-list in data frames.. But, after all, what are columns-list? on what occasions they are commonly used? they can be created with the r-base or just as…