A set in python isn't guaranteed to have any specific order. Perhaps
maintaining the keys in a separate heapq is what you want?
http://docs.python.org/2/library/heapq.html
Jason
On 7/3/13 6:47 PM, Sam Math wrote:
Thank you. This solution is much quicker, since the list of keys is kept
in or
Thank you. This solution is much quicker, since the list of keys is kept in
order!
On Wednesday, July 3, 2013 8:38:20 PM UTC-5, Volker Braun wrote:
>
> Keep both a set() and a dictionary {key:value}. Insert and delete on
> both to keep them in sync.
>
> On Wednesday, July 3, 2013 9:24:42 PM UTC-
Keep both a set() and a dictionary {key:value}. Insert and delete on
both to keep them in sync.
On Wednesday, July 3, 2013 9:24:42 PM UTC-4, Sam Math wrote:
>
> So as you can see, I'm adding 2 elements (in this case, the values are
> 1... but I have specific values in my program) to the dictiona
OrderedDict remembers the insertion order, it does not sort the keys.
The OP should just store the smallest key in an additional variable. This
just adds a constant overhead for every insert (one key comparison).
Deletion is still slow, though.
Using floats as dictionary keys opens a whole can
So I'm not sure Ordered Dictionaries will solve my pforoblem.
To clarify what I'm doing...
I'm running a loop where, with each iteration, I'm adding 2 elements to the
dictionary (each with a specific key that's a float). In addition, I'm
removing the element with the smallest key (again, it's
On Wednesday, July 3, 2013 4:58:34 PM UTC-7, Sam Math wrote:
>
> I'm looking for an equivalent to the 'map' function in C++,
> http://www.cplusplus.com/reference/map/map/.
>
> Essentially, I want an associative array. Specifically, I want the array
> to be indexed by floats.
>
> I'm aware of di