list

Reading and Grouping a List of Data in Python

I have been struggling with managing some data. I have data that I have turned into a list of lists each basic sublist has a structure like the following <1x>begins <2x>value-1 <3x>value-2 <4x>value-3 some indeterminate number of other values <1y>next observation begins <2y>value-1 <3y>value-2 <4y>value-3 some indeterminate number of...

Java Collections copy list - I don't understand

I have an ArrayList and I want to copy it exactly. I use util classes when possible ont the assumption that someone spent some time making it correct. So naturally I end up with the Collections class which contains a copy method. ss I hav the following:: List<String> a = new ArrayList<String>(); a.add("a"); a.add("b"); a.add("c"); Lis...

Where can I find useful item lists (SQL, or plain text) like sports, hobbies, and others?

GeoNames public geographic locations index is a very useful website that I have used to import a list of countries and cities into my web app. Now, are there any other public databases that would provide various useful lists? (Other than Wikipedia) I am looking for a list of sports, hobbies and similar items. ...

How to return a part of an array in Ruby?

With a list in Python I can return a part of it using the following code: foo = [1,2,3,4,5,6] bar = [10,20,30,40,50,60] half = len(foo) / 2 foobar = foo[:half] + bar[half:] Since Ruby does everything in arrays I wonder if there is something similar to that. ...

C++ standard list and default-constructible types

Why is that the single parameter constructor of std::list<T> requires T to be a default-constructible type? I mean the following code does not compile. struct Foo { // does not have default constructor. Foo (int i) {} } int main(void) { std::list<Foo> l(10); } It seems possible to use the construct and destroy idioms as they hav...

Populate a list in python

I have a series of Python tuples representing coordinates: tuples = [(1,1), (0,1), (1,0), (0,0), (2,1)] I want to create the following list: l = [] for t in tuples: l[ t[0] ][ t[1] ] = something I get an IndexError: list index out of range. My background is in PHP and I expected that in Python you can create lists that start wit...

Py3k memory conservation by returning iterators rather than lists

Many methods that used to return lists in Python 2.x now seem to return iterators in Py3k Are iterators also generator expressions? Lazy evaluation? Thus, with this the memory footprint of python is going to reduce drastically. Isn't it? What about for the programs converted from 2to3 using the builtin script? Does the builtin tool e...

How do I delete/count objects in a s3 bucket?

So I know this is a common question but there just doesn't seem to be any good answers for it. I have a bucket with gobs (I have no clue how many) number of files in them. They are all within 2k a piece. 1) How do I figure out how many of these files I have WITHOUT listing them? I've used the s3cmd.rb, aws/s3, and jets3t stuff and t...

Why doesn't jQuery Append work for the end of HTML List Items?

I'm trying to clone a list item, and then append it to the bottom of that cloned list item, note that it should be below the list item being cloned, not at the bottom of the list as I can do that myself. The purpose is to use it with jQuery.ui sortable. Everything is working fine, in fact I can even get the cloning and the appending ri...

Sort List Alphabetically

Hi, I've a List<String> object that contains country names. How can I sort this list alphabetically? Thanks. ...

safe way of allocating memory for a list node

In a simple list, ex : struct Node { Node *next; void *data; } is there any problem if i allocate Node and Data in a single allocation (provided i know the size), like Node * t = (Node*)malloc(sizeof(Node) + DataSize)); and always assign data at the end of allocated chunk, t->data = (BYTE*)t+ sizeof(Node); /* BYTE...

Array or List in Java. Which is faster ?

I have to keep thousands of strings in memory to be accessed serially in Java. Should I store them in an array or should I use some kind of List ? Since arrays keep all the data in a contiguous chunk of memory (unlike Lists), would the use of an array to store thousands of strings cause problems ? Answer: The common consensus is that t...

How can I verify that a value is present in an array (list) in Perl?

I have a list of possible values: @a = qw(foo bar baz); How do I check in a concise way that a value $val is present or absent in @a? An obvious implementation is to loop over the list, but I am sure TMTOWTDI. Thanks to all who answered! The three answers I would like to highlight are: The accepted answer - the most "built-in" ...

How to create mutlidimensional list for this in C#?

Hi, I got a table (in file) which I split into blocks by spaces. I need structure like this: ----------------------------- |21|22|23|33|3323| |32|32| |434433|545454|5454| ------------------------------ It's more like each row is its own table. How should I do this? I tried List<List<string>> matrix = new List<List<string>>(); but I...

How to sort List<List<string>> according to List<string> number of fields?

Hi, How do I sort List<List<string>> according to number of fields? The list got structure like a|b|c|d|eeee|rere|ewew| ewqewq|ewew| ewew|ewewewewew| By Sort I'd like to do it according to numbers of blockes (asc/desc) EDIT the <list<list<string>> is "items" and I access each list by items[0] each of these items[xx] is a list wh...

Picking out items from a python list which have specific indexes

I'm sure there's a nice way to do this in Python, but I'm pretty new to the language, so forgive me if this is an easy one! I have a list, and I'd like to pick out certain values from that list. The values I want to pick out are the ones whose indexes in the list are specified in another list. For example: indexes = [2, 4, 5] main_lis...

c# When should I use List and when should I use arraylist?

As the title says when should I use List and when should I use ArrayList? Thanks ...

How to sort List<List<UInt32>> according to List<UInt32>[0] number ASC/DESC in C#?

Hi, How shall sort this in ASC order? I got List<List<UInt32>> full of records of List<UInt32> and I want those records to be sorted according to the first column in each record - the column is UInt32 number. So: I have List of: new List<UInt32>: 32,1,1,1,1,1 new List<UInt32>: 22,2,2,2,2,2 new List<UInt32>: 32,1,1,1,1,1 new List<UIn...

Python: List concatenation. What is difference in "append" and "+= []"?

What is the difference in: some_list1 = [] some_list1.append("something") and some_list2 = [] some_list2 += ["something"] I hope this hasn't been already posted. If so just point me in that direction :) Thanks for your help. EDIT I've edited the title to reflect what I actually mean: "+ []" should have been "+= []". ...

Background image that shows when list is empty in Flex

How would I display a backgroundImage on a List when the List is empty? At the moment the list is populated when items are dropped inside after a drag-and-drop but I would prefer a solution that checks for any change to the data to determine if the list is empty. The List inherits a backgroundImage from its ScrollControlBase but what w...