sorting

python sort without lambda expressions

I often do sorts in Python using lambda expressions, and although it works fine, I find it not very readable, and was hoping there might be a better way. Here is a typical use case for me. I have a list of numbers, e.g., x = [12, 101, 4, 56, ...] I have a separate list of indices: y = range(len(x)) I want to sort y based on the value...

The jQuery plugin, asmSelect, doesn't retain sort order

So, I'm using the asmSelect plugin to create lists, but also trying to use it to edit existing lists. asmSelect allows you to manually sort/arrange the selected options before submitting. My problem is whenever I go and grab the user sorted list from the database and let asmSelect do its thing on my page, by default (because it's a mul...

Sort array first by length then alphabetically in Java

How can I sort an array first by length, then alphabetically? I have a list of things with numbers on them, and I am currently getting: Something1 Something10 Something2 Something3 Whereas I want to get: Something1 Something2 Something3 Something10 ...

If sorting records by a number in the record, but some records have the same number, the order is not gauranteed but shouldn't be random?

Let's say if we are sorting some records by a number in record: Name Number_of_Language_Known John 3 Mary 2 Peter 3 Mike 1 ... If we are not also sorting by Name, then the order of John and Peter is not guaranteed, but it shouldn't be random if the records never changed? I think it should be true in most environment (that is, not...

how to randomize Names that is not repeated?

i would like to make a list of names and then make a random selection but all of them should be called. off course not repeated. delphi code ...

C++ - Sort multidimensional vector by its contained object property

Hi guys, I've got a bidimensional array of objects (a 2D vector containing GridCell instances) as in here: typedef vector<GridCell> CellArray; typedef vector<CellArray> TwoDCellArray; TwoDCellArray CellArr2D; I am currently drawing all the cells like this: for (int i = 0; i < rows; i++){ for (int j = 0; j < cols; j++){ C...

jQuery DataTables plugin - secondary sorting (multiple column)

Hello, I can't find a solution for this in DataTables plugin. What I want is to have secondary sorting. What I mean by that is - for example, I have a table with product name and price, something like this: NAME PRICE A product 22.00 $ C product 50.00 $ B product 50.00 $ D p...

Algorithm of JavaScript "sort()" Function

Recently when I was working with JavaScript "sort()" function, I found in one of the tutorials that this function does not sort the numbers properly. Instead to sort numbers, a function must be added that compares numbers, like the following code:- <script type="text/javascript"> function sortNumber(a,b) { return a - b; } var n = [...

Numeric Sort in Python

I know that this sounds trivial but I did not realize that the sort() function of Python was weird. I have a list of "numbers" that are actually in string form, so I first convert them to ints, then attempt a sort. list1=["1","10","3","22","23","4","2","200"] for item in list1: item=int(item) list1.sort() print list1 Gives me: ...

Does someone really sort terabytes of data?

I recently spoke to someone, who works for Amazon and he asked me: How would I go about sorting terabytes of data using a programming language? I'm a C++ guy and of course, we spoke about merge sort and one of the possible techniques is to split the data into smaller size and sort each of them and merge them finally. But in reality, do...

sort date objects in Python

I start out with date strings: from operator import itemgetter import datetime as DT # unsorted dates raw = (map(int, "2010-08-01".split("-")), map(int, "2010-03-25".split("-")), map(int, "2010-07-01".split("-"))) transactions = [] for year, month, day in raw: new = (DT.date(year, month, day), "Some data here") t...

Group together arbitrary date objects that are within a time range of each other

I want to split the calendar into two-week intervals starting at 2008-May-5, or any arbitrary starting point. So I start with several date objects: import datetime as DT raw = ("2010-08-01", "2010-06-25", "2010-07-01", "2010-07-08") transactions = [(DT.datetime.strptime(datestring, "%Y-%m-%d").date(), ...

XSL sort functionality

<xsl:apply-templates select="$tempPosterItemNodeSet/CurrentPosterItemCollection/PosterItem" mode="PosterItem"> <xsl:sort select="$tempPosterItemNodeSet/CurrentPosterItemCollection/PosterItem/Property[@name='WidgetID']" data-type="number"/> </xsl:apply-templates> I need to xslt sort a nodeset that I am passing ...

Display navigation menu list alphabetically with jquery

Hi guys, I am hoping some smart folks can help me here. I'm out of my depth. I had a wordpress site developed for me a little while ago. I paid the developer for his work, but he never delivered what he promised so I am left to try and fix it. Anyway... The site uses some jquery to activate a drop down menu. When you click on a link cal...

sorting listbox in c#

hi, I'm using listbox in c# as a container to a user-defined objects. how can I sort the list by a class member (int) of the objects? ...

Problem with sorting jagged array.

good morning. i have a jagged array declared like int[][][] tmpA = new int[INT_WORKING_SIZE * 2][][]; I trying to sort this array with this code: Array.Sort(tmpA, 0, INT_WORKING_SIZE*2, new MyArrayComparer()); and my class: public int Compare(object x,object y) { if (x == null || y == null) return 0; ...

XSL Sort by position() giving weird results

I have an XML file whose contents I want to sort by document order (basically in the order that the items were written out). I currently use the following code: <xsl:template match="/Error"> <xsl:apply-templates> <xsl:sort select="position()" order="descending" /> </xsl:apply-templates> </xsl:template> <xsl...

Sorting a comma separated list of values

What's the easiest way to sort a comma separated list of values in Mac OS X: Input: "a, b, aaa, bc" Output: "a, aaa, b, bc" I'd like to do this from the terminal so that I can pipe the output to another command. ...

How to sort wordpress pages?

I have created 9 pages which is I ordered from 1-9 what I want is to list or display the pages link from 1-6 and also pages from 7-9 separately in header. My question how can apply this code "SELECT * FROM wp_db WHERE pages <=6" to wordpress? or to apply with this code wp_list_pages or is there another way to code it in wordpress? ...

Sorting a two-dimensional toroidal array with rotations and swaps

I tried thinking of an algorithm, but couldn't do it. Here is the problem: There are 16 elements, grouped by four types (a, b, c and d). We also have four groups, A, B, C and D. In the initial state, the four groups have four random elements each, eg.: A: c, c, a, d B: b, b, a, a C: b, b, c, c D: d, d, d, a The order of elements in ...