[Tutor] SQLite3 DB Field Alphabetizing
Steven D'Aprano
steve at pearwood.info
Tue Oct 12 14:55:05 CEST 2010
On Tue, 12 Oct 2010 10:41:36 pm David Hutto wrote:
> When calling a sqlite3 db file in python 2.6 on Ubuntu, I get the
> following when the items are taken from the db tuple, lstripped('u'),
> and added to a list.
>
> ['.hjvkjgfkj/bdgfkjbg', 'bbbbbbbbbbbbuuzzzzzzzzz', 'jgkgyckghc',
> 'kfhhv ', 'khfhf', 'test', 'test10', 'test2', 'test3', 'test346w43',
> 'test4', 'test5', 'test6', 'test7', 'test7uyuy', 'test8', 'test9',
> 'testgraph', ';s;juf;sfkh', 'zzrerhshhjrs']
>
> My question is, why is everything except [:-2] in alphabetical order?
*shrug*
Perhaps they were added to the DB in alphabetical order, except for the
entry starting with a semi-colon? Who supplied the database and how did
they insert the data?
Perhaps it's some artifact of whatever internal optimizations the DB
uses? I expect the DB table is something like a hash table, only more
complicated, so it's not impossible that the hashing function used ends
up storing items in almost-but-not-quite alphabetical order.
Maybe it's just a fluke. They have to be in *some* order.
Since you haven't told us how you added them to the list, perhaps you
deliberately added them in that order and are trying to trick us. In
which case, HA! I see through your cunning trick!
*wink*
--
Steven D'Aprano
More information about the Tutor
mailing list