newbie: for loop within for loop question
lawtonpaul at gmail.com
Mon Jun 16 03:31:02 CEST 2008
thanks for your reply. unfortunately i accidentally posted only half
of my question! the "real" post should be up now.
On Jun 16, 10:15 am, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Sun, 15 Jun 2008 17:18:54 -0700 (PDT), takayuki
> <lawtonp... at gmail.com> declaimed the following in comp.lang.python:
> > Hi everyone,
> > I'm studying python via the excellent "how to think like a python
> > programmer" book by Allen Downey. Noob question follows...
> > I have a txt file (animals.txt) which contains the following text each
> > on a separate line: aardvark, bat, cat, dog, elephant, fish, giraffe,
> > horse, inchworm, jackelope
> > I want to create a function that loops through the animals.txt file
> > and does *not* print the word if any of the user specified letters are
> > in that word.
> > def hasnolet(x):
> Hope this wasn't a homework assignment... It gave me my first excuse
> to try the set module...
> >>> import sets
> >>> words = [ "aardvark", "bat", "cat", "dog", "elephant", "fish" ]
> >>> exclude = "want"
> >>> excludeset = sets.Set(exclude)
> >>> excludeset
> Set(['a', 't', 'w', 'n'])>>> for w in words:
> ... if not excludeset.intersection(w):
> ... print w
> Wulfraed Dennis Lee Bieber KD6MOG
> wlfr... at ix.netcom.com wulfr... at bestiaria.com
> (Bestiaria Support Staff: web-a... at bestiaria.com)
More information about the Python-list