[Tutor] data structure question
alejck at gmail.com
Fri Jan 18 20:06:26 CET 2008
I'm trying to write a small todo list/task manager and I'm having
trouble creating the right data structure to hold the tasks. The
program should have a command line interface.
This is what I want it to do:
* A list of tasks, where each task has a number of attributes.
Each task should be able to have subtasks.
* A way to display all the tasks, with subtasks indented.
* A way to filter/search on the attributes of the tasks.
What I've tried so far is something like this:
def __init__(self, cargo, children=):
self.cargo = cargo
self.children = children
s = '\t'.join(self.cargo)
self.children = self.children + [child]
cargo is a list of the attributes of the task, such as task text,
status, deadline etc
What I'm having trouble with is:
* What data structure should all the Task instances be held in?
* How to traverse all the tasks, both with recursion into the subtasks
and not. I need the traversal both to create a nice string with the
task information for printing (here I need level-aware indentation),
and to be able to search the tasks by their attributes.
I suspect what I need is a tree, but I want one with multiple roots. I
only envision having <100 tasks at any one time so I don't need a
database backend. Persistence I think I've solved by having the
container data structure dump/load itself using pickle.
More information about the Tutor