[Tutor] Response to responses about list of lists: a meta exercise in mailinglist recursion

David Hutto smokefloat at gmail.com
Tue Jul 13 19:20:37 CEST 2010

On Tue, Jul 13, 2010 at 8:40 AM, Siren Saren <siren99 at yahoo.com> wrote:

> I'm not sure if there's a way to submit responses 'live' or whether it's
> better to respond to subthreads at once or together, so I'll err on the side
> of discretion and just send one response.  Thanks to each of you who tried
> to help me.  I've responded individually below.
>  To summarize the discussion so far:
> I wondered if there was a decent way to sort a list that contained two
> lists, where each could be distinguished based on the list's sequence and
> the elements' data characteristics.  As a subsidiary question, I wondered
> if there was a data structure I should aspire to put the data into once I
> had it sorted.
> In response to the first question: the consensus seems to be that there is
> no good way to sort a non-alternating one-to-many list like this, so my
> strategy of deriving the index numbers of every item, as awkward as it
> appears, may actually be the best approach.
>  In response to the second: a pickle, a dictionary, a database, and a
> tuple with a sublist were all proposed.    The choice seems somewhat
> arbitrary, but on the bright side, I suppose that also confirms that I have
> a lot of flexibility in what I choose.
> Specific responses:
> Steven,
> I apologize for using 'reply,' I've never used a mailing list before and
> didn't understand what would happen.  Is there some online forum where I
> could post a message directly rather than mailing it in?  I see that other
> people are somehow responding to my message from the more real-time updates
> I can get on activestate, but I don't know how they are doing it since I
> haven't received the mailing yet that would include my message and its
> responses.
> If my list had a million books in it and 10 million page numbers, would the
> approach I've outlined in my initial post be the best for sorting them?  Like
> David and Eric you've given me some good input on a data structure to use.
> If I understand you right, you'd advocate using a tuple of the books,
> bookmarks, where the bookmarks themselves are sublists.
> David, Yes, I agree it would  be much better to store the data in a
> different manner.  The problem is that I'm not the creator of the data.

This, again is a newbie statement but maybe importing re or regular
expressions to parse the known files would be helpful.

The way I'm thinking is that you put your books in a directory. Now, that
directory could contain directories of books with the individual text pages
within those book's directories, or something like a pdf.

Within these documents or directories, you search with an app for those
specific files. Now you can either list within the app those books and pages
and then search the directories, or you could search the directories first
and list the books, then specify the page you want to go to.

My DB idea would work if you placed in an ID, a page number, then a location
to the text file , or stored the text in the sqlite DB globfield .

> Maybe you realize that and are just suggesting the database structure
> rather than a dictionary or a pickle, once I get my sorting accomplished?
> If the book example is confusing how about this.  Say you discovered a
> bunch of data in a secret code document.  You know the sequence of the
> data relates the elements to each other.  You also know there are just two
> elements and that the sequence is a straightforward function of say,
> integers to letters.  So the data you've discovered looks like:
> A 2 3 B 4 7 5 9 1 C 3 2 1 0 0 4 D 3 3 32 44 ...
> Once I've sorted the data, I am curious how to best store it (and why), and
> your answer does pertain to that-- use sql--

Not just sql, but maybe, and dicts/lists are not my specialty yet, but
utilize it in the process. The main objective of utilizing the DB, in MHO,
is that it forces you to state the information you want to use, so this
refines your code, by defining the fields you must use to state and store
the data. So you have a book, and a page, and a author, and an id to match
these with.

Now you could use an app to search the 'book' directory, and then  'for each
in' print the book containing folder's name., then open() the page and could
go further to bring up the exact line/paragraph of the individual page.

> but I am also curious if there's a less arcane approach than the one I'm
> using to try to do the initial sorting.  Any thoughts, given that I can't
> fix the way the data arrives?  Thanks for the database idea regardless.
This again would be regular expressions, as far as I'm thinking, import re,
help(re) or dir(re), or pydoc re, or something like that. You parse the
book's file or directory, and look for the tags to read out the book's name,
author or page, and then you can just select the book, type in the page
number, or select from a predetermined list of pages that have explanations
as to why you should visit the page, or read the text.

> Eric, I appreciate your input though I'm hard-pressed to find its
> applicability.  It may be useful as a way to store my data for this or any
> number of other programs though, and that was a helpful article about the
> pickling process.  I don't know if pickle has any built-in methods for
> relating data to other data.  I'd imagine that if I were designing the
> data input process, rather than just taking data that exists and trying to
> process it, I'd probably go with a database for a situation like this.  Then
> I'd have a more explicit system for referring each value to other values
> through records, rather than having to infer them as I'm doing.  Regardless,
> I'm often in the same position of trying to be helpful without knowing how,
> and I sincerely do appreciate the attempt.  It creates a general
> atmosphere of friendliness, which is so much better than being told I'm an
> idiot :)!
> Lingering Questions:
> Anyone have a rationale for choosing one of the data structures proposed?
> Anyone have a better way to do the sorting than the process I outlined in
> my first post (a. identify the elements. b. make a list of one of  the
> element groups. c. get the index numbers of that group in the broader list.
> d. list the other elements as indexes falling between the first group's
> indexes.  e. reorganize the data into a more logical form)
> Thanks again to everyone who responded!
> Soren
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100713/3de3c633/attachment-0001.html>

More information about the Tutor mailing list