473,394 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Yet another ordered dictionary implementation

What up yalls,

Since i've been giving it all that all over the ordered dictionary thread
lately, i thought i should put my fingers where my mouth is and write one
myself:

http://urchin.earth.li/~twic/odict.py

It's nothing fancy, but it does what i think is right.

The big thing that i'm not happy with is the order list (what Larosa and
Foord call 'sequence', i call 'order', just to be a pain); this is a list
of keys, which for many purposes is ideal, but does mean that there are
things you might want to do with the order that you can't do with normal
python idioms. For example, say we wanted to move the last item in the
order to be first; if this was a normal list, we'd say:

od.order.insert(0, od.order.pop())

But we can't do that here - the argument to the insert is just a key, so
there isn't enough information to make an entry in the dict. To make up
for this, i've added move and swap methods on the list, but this still
isn't idiomatic.

In order to have idiomatic order manipulation, i think we need to make the
order list a list of items - that is, (key, value) pairs. Then, there's
enough information in the results of a pop to support an insert. This also
allows us to implement the various other mutator methods on the order
lists that i've had to rub out in my code.

However, this does seem somehow icky to me. I can't quite put my finger on
it, but it seems to violate Once And Only Once. Also, even though the
above idiom becomes possible, it leads to futile remove-reinsert cycles in
the dict bit, which it would be nice to avoid.

Thoughts?

tom

--
I content myself with the Speculative part [...], I care not for the
Practick. I seldom bring any thing to use, 'tis not my way. Knowledge
is my ultimate end. -- Sir Nicholas Gimcrack
Nov 26 '05 #1
0 905

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

210
by: Christoph Zwerschke | last post by:
This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an "ordered dictionary" class at least in the standard list? Time and again...
8
by: Fuzzyman | last post by:
Sorry for this hurried message - I've done a new implementation of out ordered dict. This comes out of the discussion on this newsgroup (see blog entry for link to archive of discussion). See...
22
by: bearophileHUGS | last post by:
>From this interesting blog entry by Lawrence Oluyede: http://www.oluyede.org/blog/2006/07/05/europython-day-2/ and the Py3.0 PEPs, I think the people working on Py3.0 are doing a good job, I am...
6
by: bearophileHUGS | last post by:
I have found that in certain situations ordered dicts are useful. I use an Odict class written in Python by ROwen that I have improved and updated some for personal use. So I'm thinking about a...
1
by: Fuzzyman | last post by:
After a break of almost a year there has been an update to `odict the Ordered Dictionary <http://www.voidspace.org.uk/python/odict.html>`_. The latest version is 0.2.2, with changes implemented...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.