On 28/08/07, Che M <[EMAIL PROTECTED]> wrote: > Hi, I am curious about ways in Python to approach the idea of "tagging" > pieces of information much in the way that one can tag favorite websites > like on the site Del.icio.us. I'm not sure if tagging is the best term for > this (due to confusion with HTML tags), but the idea would be a way to > assign one or more words to stored data such that later one might search by > those words in order to retrieve the data. That data might be a chunk of > text, a graph, image, whatever...the point would be to be able to search > later by tags name. I know the prorgram GyrFalcon uses tags and is written > in Python. And of course Flickr and many other things.
A simple way to do this in-memory would be to use a dict: keys are tags and values are sets (or lists) of objects. You might need to maintain an inverse structure too, mapping object to list/set of tags. You could use a database (sqlite comes with python 2.5). I'm not sure what the "best practice" strucutre would be, but maybe you could have a table with two columns: "object ID" and "tag". "object ID" would be some kind of identifier for your tagged objects. You could then: Find tags for an object: select tag from tagTable where objectID = ? Find objects matching a tag: select objectID from tagTable where tag = ? -- John. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor