views:

434

answers:

2

I'm developing a Sirius XM radio desktop player in Python, in which I want the ability to display a table of all the channels and what is currently playing on each of them. This channel data is obtained from their website as a JSON string.

I'm looking for the best data structure that would allow the cleanest way to compare and update the channel data.

Arrays are problematic because I would want to be able to refer to an item by its channel number, but if I manually set each index I lose the ability to sort the array, as it would remap the index sequentially (while the channels aren't in a perfect sequence).

The other possibility (I can see) is using Sqlite, however I'm not sure if this is overkill.

is there a cleaner approach for referring and maintaining this data?

+4  A: 

Why not a dict, with channel number as the key and "what's playing" as the value? Easy to make from JSON, easy to sort (sorted(thedict) sorts by channel, sorted(thedict, key=thedict.get) sorts by value -- all operations are pretty easy (if you specify better exactly what operations you want to do I'll be happy to show corresponding code samples).

Alex Martelli
+2  A: 

In this kind of situation, I often use a dict. It looks to me as the simplest solution.

I think that Sqlite will cause some unecessary overhead. However it would give you persistence of data. But I guess that your app needs to be online so you don't really need persistence

luc