[Tutor] New to programming question

2005-04-12 Thread Ben Markwell
This is an exercise from "How to think like a Computer Scientist." The following example shows how to use concatenation and a for loop to generate an abecedarian series. "Abecedarian" refers to a series or list in which the elements appear in alphabetical order. For example, in Robert McCloskey

Re: [Tutor] New to programming question (Ben M.) (Joseph Q.)

2005-04-13 Thread Ben Markwell
Thanks for everybodys input. Am learning slowly but surely. Ben On 4/13/05, [EMAIL PROTECTED] <[EMAIL PROTECTED] > wrote:Quoting Joseph Quigley <[EMAIL PROTECTED] >:> prefixes = 'JKLMNOPQ'> suffix = 'ack'>> for letter in prefixes:>  if letter == ('O') or ('Q'):>   print letter + 'u' + suffix> 

[Tutor] Question regarding the len function of a list while using a loop

2005-04-14 Thread Ben Markwell
Could somebody explain to me why the code I used to complete this exercise doesn't work. And how do you send an integer to len? Thanks Ben == As an exercise, write a loop that traverses a list and prints the length of each element. What happens if you send an

Re: [Tutor] Question regarding the len function of a list while using a loop

2005-04-14 Thread Ben Markwell
Yes this does make sense.  Thank youOn 4/14/05, Brian van den Broek <[EMAIL PROTECTED]> wrote: Ben Markwell said unto the world upon 2005-04-14 08:14:> Could somebody explain to me why the code I used to complete this exercise > doesn't work.> And how do you send an integer to

[Tutor] Trying to enter text from a file to a Dictionary

2006-01-26 Thread Ben Markwell
Being new to programming, I made a text file that contains terms with their definitions that I have come across in my studying. As an exercise, I thought  I would make a glossary using a dictionary so I can look up words, add new words, view all entries, etc.  I want to enter the words and def

[Tutor] Fwd: Trying to enter text from a file to a Dictionary

2006-01-27 Thread Ben Markwell
Hello Danny Thanks for replying to my post. >   I tried :>>   for line in f:Thanks for your reply to my post. >   gloss[line] = f.readline()> This should have worked, but there's one problem.  Whenever we're doingsomething like:for line in f:...there can be some interference bet

Re: [Tutor] Fwd: Trying to enter text from a file to a Dictionary

2006-01-27 Thread Ben Markwell
Hi Ben,Yes, that's the point: Python doesn't know when to stop.  *grin* The way we've rewritten the loop:while True:...is an "infinite" loop that doesn't stop unless something in the loop'sbody does something extraordinary, like "breaking" out of the loop. Python is much dumber than we

Re: [Tutor] Trying to enter text from a file to a Dictionary

2006-01-27 Thread Ben Markwell
On 1/27/06, Bob Gailer <[EMAIL PROTECTED]> wrote: Bob Gailer wrote:> Alan Gauld wrote:>>> Hi Ben,> I want to enter the words and definitions from the  text file into the>>> dict.>>> The way the text file is set up is that one  line is the word and the >>> next line is the definition.>>>

Re: [Tutor] Trying to enter text from a file to a Dictionary

2006-01-27 Thread Ben Markwell
> I understand f.next(), but [gloss.setdefault(l,f.next()) for l in f]> is beyond me at this point. [expr for l in f] is a "list comprehension". expr is an _expression_ thatmay involve l.result = [expr for l in f] # is equivalent to:result = []for l in f:result.append(expr) "list comprehension"