KraftDiner <[EMAIL PROTECTED]> wrote:
> Many thanks everyone.
>
> One last quick question...
> The dictionary, I believe, is sorted by the key.
Dictionaries are NOT sorted -- they're hashtables.
> Is there a way to sort it by the value?
> Say I wanted to put out a list of the frequency sorted b
KraftDiner wrote:
> Many thanks everyone.
>
> One last quick question...
> The dictionary, I believe, is sorted by the key.
> Is there a way to sort it by the value?
> Say I wanted to put out a list of the frequency sorted by highest to
> lowest?
>
The dictionary itself is actually unordered; a
Many thanks everyone.
One last quick question...
The dictionary, I believe, is sorted by the key.
Is there a way to sort it by the value?
Say I wanted to put out a list of the frequency sorted by highest to
lowest?
--
http://mail.python.org/mailman/listinfo/python-list
Hi
you can use has_key() to check whether
the particular value is in the key set or not.
>>> a = {}
>>> a[1] = 22
>>> a[2] = 33
>>> a
{1: 22, 2: 33}
>>> a.has_key(3)
False
>>> a.has_key(1)
True
>>>
-raj
KraftDiner wrote:
> Ok so this is nice.. Just one thing.. When you try to get a value from
>
KraftDiner wrote:
> Ok so this is nice.. Just one thing.. When you try to get a value from
> a dictionary
> and it isn't found in the dictionary things go bad...
>
> Take this for example:
>
> class histogram(object):
> def __init__(self):
> self.histo = {}
>
> def upda
Ok so this is nice.. Just one thing.. When you try to get a value from
a dictionary
and it isn't found in the dictionary things go bad...
Take this for example:
class histogram(object):
def __init__(self):
self.histo = {}
def update(self, point):
i
KraftDiner wrote:
> The dictionary is sorted by the point key.
> Is there a way to sort the dictionary by the value?
> Seems to me this goes against the purpose of a dictionary but
> thats what I need to do..
>
Well, it's probably not all that efficient, but it is simple code:
sortedList = [
The dictionary is sorted by the point key.
Is there a way to sort the dictionary by the value?
Seems to me this goes against the purpose of a dictionary but
thats what I need to do..
--
http://mail.python.org/mailman/listinfo/python-list
KraftDiner <[EMAIL PROTECTED]> wrote:
> Cool.
> Ok so my histogram class had two methods 1) To increment a point and 2)
> to get the point.
>
> def class histo:
>def __init__(self):
>histo = {}
> def update(point):
>'''searches the dictionary for point and if it exists increment t
On Wed, 2006-02-01 at 19:06 -0800, KraftDiner wrote:
> Cool.
> Ok so my histogram class had two methods 1) To increment a point and 2)
> to get the point.
>
> def class histo:
>def __init__(self):
>histo = {}
> def update(point):
>'''searches the dictionary for point and if it exis
Cool.
Ok so my histogram class had two methods 1) To increment a point and 2)
to get the point.
def class histo:
def __init__(self):
histo = {}
def update(point):
'''searches the dictionary for point and if it exists increment the
value.
if it doesn't exist set the value to 1'''
KraftDiner <[EMAIL PROTECTED]> wrote:
...
> histo = {[0,0,0]:1, [0,0,1]:2}
> Would indicate that there is one sample at 0,0,0 and two samples at
> 0,0,1
> but python tells me TypeError: list objects are unhashable
>
> So any suggestions would be welcome.
Use tuples, not lists, as your keys:
h
Hi, I wrote a C++ class that implements an n dimensional histogram in
C++, using stl maps and vectors. I want to code this up now in Python
and would like some input from this group.
The C++ class was VERY simple..
std::map, unsigned long> histo;
Say for example I want a 3D histogram th
13 matches
Mail list logo