> 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"
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.>>>
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
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
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
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
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
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>
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