Questions tagged [sorteddictionary]

Represents a collection of key/value pairs that are sorted on the key.

Filter by
Sorted by
Tagged with
-1 votes
3 answers
52 views

Order dict by value

I have an initial dict named grouped_items and i need to populate it via grouped_items = { "tcp_permit": [], "tcp_deny": [], "udp_permit": [], "...
as path prepend's user avatar
0 votes
1 answer
15 views

How to sort a dictionary inside a dictionary by values?

I am trying to sort this dictionary that contains divisions of hockey teams. Each team is an element of the dictionary and each team's value is a dictionary that has a number of points (PTS) and a VRP ...
Popcycle999's user avatar
0 votes
1 answer
54 views

SortedDictionary with class for a key becomes unsorted

SortedDictionary is supposed to always be sorted by its key. Now consider the following code: public class ContentKey { public int key_num = 0; } public static void Main(string[] args) { ...
DragonGamer's user avatar
-1 votes
1 answer
26 views

Sorting the SortedDictionary keys using for each

Good afternoon. I have a strange problem. When iterating through the list, SortedDictionary does not recognize the key. Namely, it gives out that the key was not found. System.Collections.Generic....
RedToni's user avatar
1 vote
1 answer
89 views

Time complexity for accessing a value in a dictionary [duplicate]

I'm trying to understand why time complexity of accessing a value in a dictionary is O(1). If I understand correctly, a dictionary is essentially an associative array, i.e. an array A of size n where ...
Renato Dias's user avatar
0 votes
3 answers
71 views

How to sort Dictionary based on keys where key contains Month Year expression of DateTime as String

I am trying to sort below Dictionary Dictionary<string, int> map = new Dictionary<string, int>(); map["Sep 20"] = 10; map["Oct 20"] = 11; map["Nov 20"] = 23; ...
Sawan Meshram's user avatar
0 votes
1 answer
150 views

Sorting dictionary by keys that are dates

When developing a telegram bot, you need to sort the dictionary by date, to output news in chronological order. The problem is the difference in key formats (dates). There is the format %d.%m at %...
Apple's user avatar
  • 13
0 votes
0 answers
41 views

Do I need to define comparer for values inside sortedDictionary?

I have sortedDictionary where key is float and value is some class i wrote. I try to use myDictionary.Max(), but I get an argument exception: ArgumentException: At least one object must implement ...
Crimsoon's user avatar
0 votes
1 answer
34 views

How can I order entries in my OrderedDict where values are duplicated?

I have a bunch of code that is out of scope of this question. The code scrapes data and gives me the following dictionary: {'Male Open 60 Mins': {'Kavin Jones': {'total_points': 47, 'plate_number': '...
Eddi's user avatar
  • 179
1 vote
1 answer
67 views

How to sort multiple columns values from min to max, and pivot them using python?

I have a dataframe with datetime objects in columns 'start' . I want to sort these dates into new columns : evry time ID start to a new location with order df = pd.DataFrame(data={'ID':['a1','a2','a1',...
phœnix's user avatar
  • 367
0 votes
3 answers
71 views

how to find the most popular letter in a string that also has the lowest ascii value

Implement the function most_popular_character(my_string), which gets the string argument my_string and returns its most frequent letter. In case of a tie, break it by returning the letter of smaller ...
Libi's user avatar
  • 35
1 vote
3 answers
69 views

Subtracting elements from sorted dictionary in Python

I have a sorted dictionary (here the bids of an order book) with the following form, where the items in the parentheses are {price: amount} and sorted. bids = SortedDict({0.0005: 11.0, 0.006: 10.0, 0....
Julien's user avatar
  • 35
-1 votes
1 answer
86 views

How can we have SortedList as a parameter in SortedDict in Python?

I am trying to use SortedList from sortedcontainers library as a parameter for SortedDict. Even though the Initialization maps = SortedDict(SortedList()) worked. I am Unable to insert any data into ...
Avinash Doddi's user avatar
1 vote
2 answers
157 views

Time complexity iterating over items in a SortedDict?

from sortedcontainers import SortedDict d = SortedDict(b=20, d=30, c=10, e=50, a=40) # What is the time complexity of the following code? for k, v in d.items(): print(k, v) I think the time ...
noobie2023's user avatar
0 votes
1 answer
71 views

Cassandra : map map<text, text> datatype of UDT to SortedDictionary in .Net

I am using cassandra DB for .Net. I have created a datatype dictionary_type_property map<text,text> inside user defined datatype, but facing problem while converting this datatype value to .Net ...
Srini V's user avatar
  • 65
0 votes
1 answer
766 views

How to change index values of a dict?

Is it possible to change the values of a sorted dictionary? After sorting the dict alphabetically I got a result like this: OrderedDict([('a', {'index': 3, 'parent': None}), ('a/b', {'...
N13's user avatar
  • 27
-1 votes
2 answers
453 views

Sort the dictonary of objects by the attribute of the obejct

A dictionary that has a key, the value it is a object of class with attributes dic = { 1:Person("John, Greenberg", 3), 2:Person("Thomas, San", 5), 3:Person("...
Leanne's user avatar
  • 1
1 vote
0 answers
176 views

Accessing Min/Max key from SortedDictionary in O(1)

I have a (large) SortedDictionary<TKey,TValue> and I need to access the min/max keys efficiently, presumably in O(1) time since the keys are "sorted". How do I do this?
Herman Schoenfeld's user avatar
0 votes
1 answer
90 views

python type of SortedDict can not be defined

How can I define the type of SortedDict? from typing import Dict from sortedcontainers import SortedDict x: Dict[int, str] = {2: "two"} y: SortedDict[int, str] = {3: "three"} # &...
OrenIshShalom's user avatar
2 votes
1 answer
173 views

Why SortedDictionary.GetEnumerator() is an O(log n) operation in C# according to Microsoft Docs?

According to Microsoft Doc, the SortedDictionary.GetEnumerator() method is an O(log n) operation in C#. SortedDictionary is backed by SortedSet. Looking at .NET source line 1911 to 1923, when the ...
Farhad Shariatzadeh's user avatar
2 votes
2 answers
423 views

SortedDict key: TypeError: '<' not supported between instances of 'str' and 'int'

Please, help me to understand why setting key parameter of SortedDict in the following code: from sortedcontainers import SortedDict SortedDict({1:2, 0:1}) # works SortedDict({1:2, 0:1}, key=lambda x: ...
S.V's user avatar
  • 2,391
0 votes
0 answers
20 views

Sort "A-1" before "A-10" in .net SortedDictionary *without* LINQ [duplicate]

I'm sure this is an FAQ, but the first 12 items Google returned do not have this question in it. I have a SortedDictionary(of String, String) where the first item is an apartment number and the second ...
Maury Markowitz's user avatar
-1 votes
2 answers
207 views

Create sorted dictionary from dictionary in vb.net

I'm trying to adapt code written in C# into a vb.net application. At one point a variable of type Dictionary is converted to a variable of type SortedDictionary. I've re-written it in vb.net, but it ...
boilers222's user avatar
  • 1,911
2 votes
1 answer
2k views

Performance of SortedDictionary vs sorting a Dictionary

I have a list of objects. These objects have many properties including price and quantity. I need to create a new dictionary with key 'price' and value 'quantity'. If two objects have the same price, ...
user147504's user avatar
3 votes
0 answers
184 views

Does Linq.First() method return the first entry of a SortedDictionary in O(1) in C#?

I know the Last() method of Linq returns the last entry of a SortedDictionary in O(n) because it needs to enumerate through all the entries. What about the First() method? Is it O(1) since it's ...
Farhad Shariatzadeh's user avatar
0 votes
1 answer
700 views

Get nearest key above or below in a C# SortedDictionary [duplicate]

This is related to Equivalent of Java's SortedMap.tailMap in C# SortedDictionary, but my requirement is slightly different so I'm hoping there might be a better solution. I have a SortedDictionary,...
Michael Kay's user avatar
4 votes
1 answer
354 views

How to set initial capacity to a SortedDictionary?

I'm looking into code optimization of a project of mine and I was wondering how can I set an initial capacity to a SortedDictionary. I know that I can do it to a List and a Dictionary pretty easily in ...
Lucas Ferreira's user avatar
0 votes
1 answer
44 views

How to sort a dictionary list with multiple values related to one single key name and convert it to float numbers

I'm a beginner at Python and I'm trying to figure out a paper I have to do for school. So the situation is that I have a csvfile under DictReader and want to be able to not only sort all the values ...
Kevin Ariel Arduengo Romero's user avatar
0 votes
0 answers
23 views

Is a SortedList or SortedDictionary the best way to efficiently store and retrieve data by the nearest key?

I am working on a project where I'm storing an object inside a SortedList<float, myData> with timestamps as a key so that I can use the built in binary search to retrieve the data (or two sets ...
Carter Sondrol's user avatar
1 vote
1 answer
47 views

Swapping values in a sorted object map

Lets say I have an sorted dictionary whose keys are objected public class ExecutionMap { protected SortedDictionary<object, object> ExecutionMap { get; set; } } Lets say I lets say I have ...
johnny 5's user avatar
  • 20.2k
1 vote
0 answers
137 views

Implement Suffix Tree

Good afternoon. I am trying to rewrite the code from C ++ to python, but I get a key error: 0 in the last lines: for c in range (256): link [0] [c] = 1; I've looked at a sample for adding a value to a ...
mraklbrw's user avatar
0 votes
0 answers
27 views

How to properly implement data binding for a SortedDictionary [duplicate]

In a WPF application, I am using a DataGrid on my main window. The data that it displays is from a SortedDictionary<int, Individual> , where Individual is a class containing a person’s name and ...
G. M.'s user avatar
  • 9
0 votes
2 answers
75 views

How to sort an array from a specific key?

Currently, I have an array declared as : let VitamineARetinol = "VitamineARetinol" let VitamineABetacarotene = "VitamineABetacarotene" let VitamineC = "VitamineC" let ...
Wahib's user avatar
  • 93
0 votes
0 answers
56 views

Summation of SortedDictionary in C# on the basis of specified intervals of keys

This is how initially value looks After doing the sum of values based on specified interval, in this case, it summed values for keys in an interval of 0.5 Currently, it is being done with the help of ...
Nishant Garg's user avatar
-1 votes
2 answers
50 views

Sort list of below dictionary in descending order

I have the below dictionary and i want sorted dictionary dict1 = {'years': [{'doc_1': 1}, {'doc_2': 0}, {'doc_3': 0}], 'working': [{'doc_1': 1}, {'doc_2': 1}, {'doc_3': 0}], 'experience': [{'...
Ali Zaib's user avatar
1 vote
1 answer
556 views

With a Comparer to comparer keys by their values from a dictionary, SortedDictionary always throw exception

I want to achieve a heap with SortedDictionary which compares values instead of keys. My elements are in the dictionary and I added them one by one to the SortedDictionary. It always thow exception at ...
Sylvain LIU's user avatar
1 vote
0 answers
85 views

Sort Dictionary by top 10 values, also if a value is double then it should put them on the same place from 1-10

The function I made is the following: r = 0 n = 10 checklist = [] for key, value in sorted(contribution.items(), key = lambda kv: kv[1], reverse = True): if value in checklist: print(str(...
Sara Cortesi's user avatar
0 votes
4 answers
340 views

File to dictionary only prints one

I have a text file that reads: a;b a;c a;d b;h c;e e;f e;g e;j f;b g;d h;b h;e i;d i;e but when I print it after making it into a dictionary def read_graph(file_name): ...
user avatar
-2 votes
1 answer
96 views

Index error when adding Array to SortedDictionary

I've been working on this code but have yet to see the results. It's giving me error message "Index was outside the bounds of the array". I read other posts with the same error but I couldn't fully ...
Koda's user avatar
  • 37
0 votes
0 answers
1k views

SortedDict: Sort by value in python

SortedDict is a class that inherits from dictionary and keeps elements sorted by key all the time. We can also specify for it to sort by some function of the key as follows. def func(x): return -...
Mahathi Vempati's user avatar
3 votes
2 answers
2k views

get range of values from a sorted dictionary

I have a sorted dictionary with DateTime as the key: myDictionary = new SortedDictionary<DateTime, float>(); I would like to implement the following function: data[] GetRange(DateTime From, ...
Thomas's user avatar
  • 11.2k
0 votes
1 answer
284 views

Combobox selection based on FindStringExact not working as intended

I'm trying to select the item in the Combobox based on the stored value in a Sorteddictionary String value matching comboBoxEdit3.SelectedItem = comboBoxEdit3.FindStringExact(Queries[_ucSetting....
techno's user avatar
  • 6,190
4 votes
1 answer
671 views

Custom option to Search a Sorted list faster than Plain Binary Search

Following is the use-case: Sorted List of DateTime type, with granularity in the millisecond Search for nearest DateTime, which satisfy the supplied predicate delegate Performance is an issue, since ...
Mrinal Kamboj's user avatar
0 votes
1 answer
288 views

How to check if a SortedDictionary is being added, updated or deleted in C#

I have a SortedDictionary of events which people can purchase tickets for. The event code is unique to that ticket which is stored as the key. protected SortedDictionary<int, Event> Events = ...
Jaquarh's user avatar
  • 6,568
2 votes
1 answer
138 views

How to compare values from one SortedDictionary to Add them to a new SortedDictionary?

I have 2 SortedDictionary "mainsd" && "valuesd". The conditions I'm trying to program says the following: If the sum of Values of the 2 Keys above the MaxValue in "...
Koda's user avatar
  • 37
1 vote
2 answers
51 views

Display elements from nested SortedDictionary

I have list: ProjectTaskList = new SortedDictionary<string, SortedDictionary<string, string>>(); I try to display all the elements from the list: foreach (var itemList in ...
4est's user avatar
  • 3,070
0 votes
1 answer
314 views

How to get Key of Value that is greater than three Values above and below

I've got a sortedDict = new SortedDictionary<double,double>(); And I'm trying to get the Key of the Value that is greater than the three Values above and three Values below but I don't know how....
Koda's user avatar
  • 37
1 vote
1 answer
67 views

Sorting nested ordered dictionary in Python

My original dictionary contains values of the form : [(0, {'T8': (0.3978349, 0), 'T9': (0.84942997, 0), 'T6': (1.1480641, 0), 'T7': (2.1811862, 0), 'T4': (2.016099, 0), 'T5': (1.5923926, 0), 'T2': (...
OBX's user avatar
  • 6,044
0 votes
2 answers
629 views

How to sort a dictionary in python using enumerate?

I have the following code for index,(key,value) in enumerate(dict_var.items()): sorted_dict[index] = (key, value) print("The sorted list is:{}".format(sorted_dict)) where dict_var is a ...
Ari Roth's user avatar
-1 votes
1 answer
772 views

Converting a sorted dictionary to an array

I have a program that reads an ASCII file and outputs a text file with each character and the number of times it appears in the file. A sorted dictionary was used in this program but I was wondering ...
Zane 's user avatar
  • 15