FAQ Database Discussion Community


Adding multiple values to a dictionary and then sorting it

python,dictionary,sorted
I have a file that contains three attributes: id, text and date. There are roughly 70K records in this file. I am looking to add this data to a dictionary and then sort it by date. Below is the code. matchinput = csv.reader(open(filename,"rb"),delimiter=',', quotechar='|') tweets = [] for row in...

Create a list of midpoints of a sorted list

r,vector,mean,sorted
I have a sorted vector of numeric values and I would like to create a new vector containing the midpoints of all the pairs. For example: a <- c(1,2,3,4) I want to create b such that it contains the midpoint of (1,2), (2,3) and (3,4): b <- c(1.5, 2.5, 3.5)...

Python - Cannot sort properly my list by alphabetical order

python,function,sorted
I had to create my own "sorted" function by alphabetical order, and then to use than function in an other. The aim is to sort a list by alphabetical number, my test list has 4 elements, but the final aim is to apply this function to a huge list, this...

A List of Lists containing int and string, need to output X strings with highest int values based on TrackBar (not a sorted list)

c#,string,list,sorted
I have a List structured as: "Then a sentence woop", 340 "and another one", 256 "in order they appear", 700 "in a linked file", 304 The list contains the highest scored sentence from each paragraph of a text file. I need to output each sentence, but with a track bar...

Sorting a Dict whose values are objects Python

python,list,sorting,object,sorted
I have a dict in which the values are lists of Objects. I need to sort them based on one of the object's attributes. {key1 : [(list1 of obj),(list2 of obj),(list3 of obj)], key2 : [(list1 of obj),(list2 of obj)]} I need to sort the list of values by one...

How do I sort a Python list of strftime('%I:%M %p') in django templates?

python,time,django-templates,sorted
I have a python list of time values. I have the list in the following format. How would I sort the time values in ascending order? timeSlot = [ {'timeSlot': '1:15 PM'}, {'timeSlot': '9:15 PM'}, {'timeSlot': '9:15 AM'} ] ...

In python, how do I make a collection that is sorted by one value, and indexable by another

python,collections,sorted,indexed
I need to have a collection, in which I insert items such as [1,'b42b00d6-76c8-4d68-b22e-ff4653bb01c8']. It needs to be ordered by the first element, but indexable by the second. The following is the best I could come up with. It has two flaws: It can't take multiple items with the same...

C# Sorted list without LINQ and SORT

c#,string,list,insert,sorted
My question is that is it possible to create a list that sorts the objects in it upon these object being placed in them? After not getting anywhere, I made a new linked list. The only task is to make this list ordered by the string field of the objects...

Simple merge_sort on list - analysis

c,list,function,merge,sorted
I wrote simple function, that merge two sorted list into one. Unfortunately, I couldn't get a result, I don't know why. Compilator don't show any statements, and stop working while starting the function. It seems me to be ok everything. Check that, please. Below is shown the code. node list_sort...

Python DefaultDict Ordering Multiple Values Issue

python,python-3.x,dictionary,sorted,defaultdict
I am trying to order all of the scores in order of each user's score from highest to lowest. I have attempted this with the code below: import collections from collections import defaultdict from operator import itemgetter worker_scores = collections.defaultdict(lambda: collections.deque(maxlen=3)) import operator worker_scores.clear() with open('score_names.txt') as f: for line...