Questions tagged [sorted]

This tag refers to a collection of items that has already been arranged in some specific order.

Use this tag for questions dealing with already sorted collections (i.e. reordering them, adding elements to them while still preserving the order, etc.).

297 questions
4
votes
1 answer

Can I import sorted using from __future__ in Jython?

I am stuck using the older version (2.2.1) of Jython on the machines I am working on, but I need the sorted method. I already import generators from future, but from __future__ import sorted returns SyntaxError: future feature sorted is not…
Climbs_lika_Spyder
  • 4,480
  • 2
  • 27
  • 45
4
votes
2 answers

Get the first sorted element with LINQ? (C#)

First, have a look at this code: Dictionary dict = Dictionary(); dict[3] = 1; dict[2] = 2; dict[1] = 3; foreach(KeyValuePair item in dict.OrderByDescending(p => p.Value)) { print(item.Value); break; } This code,…
Georges Oates Larsen
  • 5,924
  • 10
  • 43
  • 63
4
votes
1 answer

Why haven't Sorted JLists been made part of the standard Swing library yet?

"Creating a Sorted JList Component" says, Version 6 of the Java Platform, Standard Edition (Java SE, formerly referred to as J2SE) will add sorting and filtering abilities to the javax.swing.JTable class.* The Java Foundation Classes/Swing …
mre
  • 40,416
  • 33
  • 117
  • 162
4
votes
3 answers

Scala function to get all sorted subsets of size k

I am given a set of size L and want to generate every sorted subset of size k. Would be great if your solution is in scala but maybe I am able to translate by myself. An example run for L = 6 and k = 3 should yield. 1, 2, 3 1, 2, 4 1, 2, 5 1, 2,…
peri4n
  • 1,303
  • 13
  • 21
4
votes
5 answers

Thread-safe Sorted Collection

Is there an implementation of a thread-safe sorted collection in Python? Python's docs reference SortedCollection but I'm not sure if it's thread-safe (is it?) If there is no such implementation - how would you implement it?
Jonathan
  • 84,911
  • 94
  • 244
  • 345
4
votes
11 answers

C# Datatype for large sorted collection with position?

I am trying to compare two large datasets from a SQL query. Right now the SQL query is done externally and the results from each dataset is saved into its own csv file. My little C# console application loads up the two text/csv files and compares…
MaxGeek
  • 1,095
  • 6
  • 21
  • 31
4
votes
2 answers

What does python3 do with the methods passed to the "key" argument of sorted()?

I have a question about how python treats the methods passed to sorted(). Consider the following small script: #!/usr/bin/env python3 import random class SortClass: def __init__(self): self.x = random.choice(range(10)) self.y =…
TwentyMiles
  • 3,886
  • 3
  • 26
  • 36
4
votes
9 answers

Need a fast alternative to Java TreeMap that can hold many mappings without slowdown

I am writing a Java program that uses a TreeMap and the performance slows down to a crawl once there are 10's of thousands of integer, character mappings. I was wondering if there is an implementation of some type of sorted set implementation out…
A J M
  • 51
  • 1
  • 2
4
votes
1 answer

Retrieving JTable line content after user sorted content by clicking on column

I have a pane with two tables A and B. When a row is selected in A, the content of B should be upated. My code detects row selections in A fine. But, when the user clicks on the column header to sort rows, it does not seem like this is taken into…
Jérôme Verstrynge
  • 51,859
  • 84
  • 263
  • 429
4
votes
1 answer

Why does sorted()'s key parameter require a keyword argument

If you inspect the signature of Python's built-in sorted() function like this: import inspect print(inspect.signature(sorted)) The signature is: (iterable, key=None, reverse=False). Based on my understanding of positional and optional arguments…
user4694244
4
votes
1 answer

python - complex sorting of nested data

I am retrieving data from postgres (jsonb type) and I need to return an OrderedDict that has a predictable order for human and machine consumption. There are some common(ish) keys that should be used to direct precedence of values of common types…
rtluckie
  • 321
  • 4
  • 11
4
votes
2 answers

C++ What is the best way of reading the dictionary from text file and storing it in the sorted container

What is the best way of reading the dictionary from text file and storing it in the sorted container. I've got performance issue when inserting the words to the container. So Here is my code. std::set m_words; std::stringstream…
4
votes
1 answer

Any way to use strings as the scores in a Redis sorted set (zset)?

Or maybe the question should be: What's the best way to represent a string as a number, such that sorting their numeric representations would give the same result as if sorted as strings? I devised a way that could sort up to 9 characters per…
timbur
  • 438
  • 6
  • 10
4
votes
5 answers

merging two sorted linked lists into one linked list in python

here is my code: def merge_lists(head1, head2): if head1 is None and head2 is None: return None if head1 is None: return head2 if head2 is None: return head1 if head1.value < head2.value: temp = head1 …
srik sri
  • 53
  • 1
  • 1
  • 8
4
votes
3 answers

Advanced List sorting Python

I am trying to sort a dictionary which is in the form: d = {'+A':234, '-B':212, 'A':454, '-C':991, '-A':124} I want to sort it by key so that it is in the form: +A, A, -A, +B, B, -B, etc I have been trying to use sorted(d, key=lambda x: (x[1],…
rmoro
  • 374
  • 1
  • 11