Re: [Tutor] When am I ever going to use this?
--- Christopher Spears <[EMAIL PROTECTED]> wrote: > I've been working through a tutorial: > http://www.ibiblio.org/obp/thinkCSpy/index.htm. > Lately, I have been learning about abstract data > types > (linked lists, stacks, queues, trees, etc.). While > I > do enjoy the challenge of creating these objects, I > am > not sure what they are used for. > You probably use a linked list every day and don't even know it. Do you ever hit the "Back" button on your web browser to return to previous pages? The browser keeps a list of the pages you've visited, all linked together, so you can move backwards and forwards through the list. Here is a great resource for learning about different kinds of data structures: http://www.nist.gov/dads Regards, Marc __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When am I ever going to use this?
On Tue, 1 Aug 2006, Christopher Spears wrote: > I've been working through a tutorial: > http://www.ibiblio.org/obp/thinkCSpy/index.htm. Lately, I have been > learning about abstract data types (linked lists, stacks, queues, trees, > etc.). While I do enjoy the challenge of creating these objects, I am > not sure what they are used for. Hi Chris, Let say that we are trying to write a navigator program, one that helps plan road trips. One portion of the input to this program would be a map of the roads. For example: map = [('a', 'b'), ('a', 'c'), ('c', 'f'), ('b', 'd'), ('d', 'e'), ('d', 'f')] might represent the following street map: a -- b || || cd -- e \ | \ | - f where 'a', 'b', 'c', 'd', 'e', and 'f' are points of interest. (I'm oversimplifying, but I hope you don't mind!) A simple question we might ask this system is: how far is it from point 'a' to point 'f'? We'd like to ask the system: distance('a', 'f', map) and be able to get 2, since there's a hop from 'a' to 'c', and from 'c' to 'f'. This problem is ripe to be attacked with an algorithm called "breadth-first search", and breadth-first search typically is implemented by keeping a queue of places. We can talk about this in more detail if you'd like. http://en.wikipedia.org/wiki/Breadth-first_search This is a long hand-wavy example for a short explanation: queues and and other data structures are "background" support tools: they themselves aren't so interesting, but they're the tools that a programmer often will reach for when working on non-string related problems. If you remember Starcraft: there was a four-level queue of movement commands that you could set up by holding "shift" while navigating your forces. You could also "queue" up production orders in factories. Same data structure. *grin* Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When am I ever going to use this?
Christopher Spears wrote: > I've been working through a tutorial: > http://www.ibiblio.org/obp/thinkCSpy/index.htm. > Lately, I have been learning about abstract data types > (linked lists, stacks, queues, trees, etc.). While I > do enjoy the challenge of creating these objects, I am > not sure what they are used for. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > They all have many uses. Priority Queues are used frequently in operating systems for process scheduling, etc. Trees are fantastic for most any searching application. Linked lists can be used for general purpose storage (since unlike arrays, their size is not fixed.) Learning data structures is really the one thing i wouldn't recommend python for, just because the job is usually done for you. Why implement a linked list, when we already have lists? Then Queues and Stacks are trivial to implement once you've got lists. If you're interested in learning more about data structures and their uses, this looks like a good reference: http://www.brpreiss.com/books/opus7/ -Jordan Greenberg ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] When am I ever going to use this?
I've been working through a tutorial: http://www.ibiblio.org/obp/thinkCSpy/index.htm. Lately, I have been learning about abstract data types (linked lists, stacks, queues, trees, etc.). While I do enjoy the challenge of creating these objects, I am not sure what they are used for. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about headers and smtplib
OK, this worked, please disregard my last. The online docs at python.org told me the answer to that one. Between their example and yours, i am able to make it work. thanks a whole bunch ! shawnOn 7/31/06, Justin Ezequiel <[EMAIL PROTECTED]> wrote: When I first started with Python, I used MimeWriter to create E-mails.Then some mail servers rejected my E-mails.Some research (google) indicated (to me) that I needed a MIME-Version header.(Can't recall now if I also needed a Content-Type header.) Anyway, more research (Python docs) indicated that I should use theemail package instead.I have been doing so since and have not had reports of anymore rejected E-mails.Hope this helps.>>> import email >>> from email.MIMENonMultipart import MIMENonMultipart>>> from email.Utils import formataddr>>> format_addresses = lambda pairs: ', '.join([formataddr(pair) forpair in pairs]) >>> msg = MIMENonMultipart('text', 'plain', charset='us-ascii')>>> msg.set_payload('Foo Bar')>>> msg.add_header('From', formataddr(('Justin', '[EMAIL PROTECTED]'))) >>> msg.add_header('To', format_addresses([('Justin', '[EMAIL PROTECTED]'),('You', '[EMAIL PROTECTED]')]))>>> print msg.as_string()Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0From: Justin <[EMAIL PROTECTED]>To: Justin <[EMAIL PROTECTED]>, You <[EMAIL PROTECTED]>Foo Bar>>> ___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Debugging multithreaded programs in python
Noufal Ibrahim wrote: > Greetings all, > A friend here is trying to debug a rather badly written python program > which spawns off lots of threads here and there. Are there any > frameworks that I can reccommend that would ease his pain? > winpdb claims to debug multi-threaded programs. I have found it useful for single-threaded programs, haven't tried it for m-t. http://www.digitalpeers.com/pythondebugger/ Debugging m-t programs can be very hard. Placing a breakpoint can change the timing so a bug doesn't appear, or ruin a critical response time. Print statements can help. You say the program is badly written, if it uses more threads than needed maybe the first step is to get rid of some of them. You could also look for subsystems that could be tested independently, perhaps using unittest. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor