How to generate List from SQL query?

I think this is what you’re looking for. List<String> columnData = new List<String>(); using(SqlConnection connection = new SqlConnection(“conn_string”)) { connection.Open(); string query = “SELECT Column1 FROM Table1”; using(SqlCommand command = new SqlCommand(query, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { columnData.Add(reader.GetString(0)); } } } } Not tested, but this should work fine.

Python: Array v. List [duplicate]

Use lists unless you want some very specific features that are in the C array libraries. python really has three primitive data structures tuple = (‘a’,’b’,’c’) list = [‘a’,’b’,’c’] dict = {‘a’:1, ‘b’: true, ‘c’: “name”} list.append(‘d’) #will add ‘d’ to the list list[0] #will get the first item ‘a’ list.insert(i, x) # Insert an … Read more

How do I get a list item by index in elm?

Elm added arrays in 0.12.1, and the implementation was massively overhauled in 0.19 to improve correctness and performance. import Array myArray = Array.fromList [1..5] myItem = Array.get 2 myArray Arrays are zero-indexed. Negative indices are not supported currently (bummer, I know). Note that myItem : Maybe Int. Elm does everything it can to avoid runtime … Read more

How to make List’s Add method protected, while exposing List with get property?

As others have said, you are looking for the .AsReadOnly() extension method. However, you should store a reference to the collection instead of creating it during each property access: private readonly List<SomeOtherClass> _items; public WhatClass() { _items = new List<SomeOtherClass>(); this.Items = _items.AsReadOnly(); } public ReadOnlyCollection<SomeOtherClass> Items { get; private set; } This is to … Read more

How to efficiently (performance) remove many items from List in Java?

OK, it’s time for test results of proposed approaches. Here what approaches I have tested (name of each approach is also class name in my sources): NaiveRemoveManyPerformer – ArrayList with iterator and remove – first and naive implementation given in my question. BetterNaiveRemoveManyPerformer – ArrayList with backward iteration and removal from end to front. LinkedRemoveManyPerformer … Read more

Transpose nested list in python [duplicate]

Use zip with * and map: >>> map(list, zip(*a)) [[‘AAA’, ‘BBB’, ‘CCC’, ‘DDD’, ‘EEE’, ‘FFF’, ‘GGG’, ‘HHH’, ‘III’], [‘1’, ‘262’, ’86’, ’48’, ‘8’, ’39’, ‘170’, ’16’, ‘4’], [‘1′, ’56’, ’84’, ‘362’, ’33’, ’82’, ‘296’, ’40’, ‘3’], [’10’, ‘238’, ‘149’, ‘205’, ’96’, ’89’, ‘223’, ’65’, ‘5’], [’92’, ‘142’, ’30’, ‘237’, ‘336’, ‘140’, ‘210’, ’50’, ‘2’]] Note … Read more

bash: how to delete elements from an array based on a pattern

Filtering an array is tricky if you consider possibility of elements containing spaces (not to mention even “weirder” characters). In particular answers given so far (referring to various forms of ${x[@]//pref*/}) will fail with such arrays. I have investigated this issue somewhat and found a solution however it is not a nice one-liner. But at … Read more

Generating all possible combinations of a list, “itertools.combinations” misses some results

Use itertools.permutations: >>> import itertools >>> stuff = [1, 2, 3] >>> for L in range(0, len(stuff)+1): for subset in itertools.permutations(stuff, L): print(subset) … () (1,) (2,) (3,) (1, 2) (1, 3) (2, 1) (2, 3) (3, 1) …. Help on itertools.permutations: permutations(iterable[, r]) –> permutations object Return successive r-length permutations of elements in the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)