I'm fairly new to programming and Python as well, but I have a suggestion that may be worth looking into-- are you familiar with pickling? It sounds like something that may fit in well with what you're trying to do.<br>
<br>Good reference article:<br><br><a href="http://articles.techrepublic.com.com/5100-10878_11-1052190.html">http://articles.techrepublic.com.com/5100-10878_11-1052190.html</a><br><br><br><div class="gmail_quote">On Mon, Jul 12, 2010 at 5:19 PM, Siren Saren <span dir="ltr"><<a href="mailto:siren99@yahoo.com">siren99@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font: inherit;" valign="top">
I'm still fairly new to programming. Python is my first language and I am teaching myself as best I can. I'm struggling with a situation that I expect must come up all the time. I can come up with relatively complicated solutions but I wonder if there's not a more pythonic way of doing it.<br>
<br>I've seen a lot of examples in books for dealing with lists of alternating data types, but what about a list that doesn't follow a simple numeric pattern? For example, say I have a list that's a composite of two elements: books and key pages / albums and favorite tracks / medicines and times taken, whatever. To make a program that does something to the first set of elements based on the second set of elements, what kind of structure should I set up? <br>
<br>Probably easier to choose one of these. So pretend I have a list like
this:<br><br>(Crime and punishment, page 10, page 40, page 30, Brother's Karamazov, page 22, page 55, page 9000, Father's and Sons, page 100, Anna Karenina, page 1, page 2, page 4, page 7, page 9)<br><br>Since I can identify the elements and since I know the values are 'in order,' in other words the page numbers between the first and second book all belong to the first book, I can make a mapping. But I've been surprised at the complexity. So in this hypothetical, with a regular expression, I can easily convert the pages to integers, and identify the two lists. But what's the right way to map them to each other, if I am planning to, for example, tear out these key pages and make a wall hanging. (I would never do this with precious books like these, of course). Am I right to think that I want to get them into a form that clearly relates them to each other from the outset? Does a dictionary make sense-- I've read that I
should expect to put a lot of my data into dictionaries?<br><br>My tentative approach has been as follows:<br><br>a. Make a sublist of the Books. Here we could just get the non-integers so Books = ('C and P', 'Brothers K' ...)<br>
b. Look each up book in the main list to get an index values<br>c. Now my approach becomes ugly. In pseudo code-<br><br>For book in Books:<br> A dictionary should map the book to a list of all the elements in the main list that fall between the book's index value and the next book's index value<br>
<br>I keep coming up with embedded loops to express this but I simultaneously feel like I am missing a third layer (somehow maybe it's 'for book,' 'for index,' 'for element'?) and like Occham is going to come by with his razor and laugh at me and say, "oh there's a function that does this called the "one to many mapping function." <br>
<br>I think I'm reading the right books and going to the
right web pages and such to learn, but in this case, I must have just not comprehended. Would be grateful for any input. Have enjoyed reading the archives of this group as I've been trying to get my head around programming. Thanks again<br>
<br>Soren<br><br></td></tr></tbody></table></blockquote></div><br>