[Tutor] Best Practice: Subroutines and Loop logic
GoodPotatoes
goodpotatoes at yahoo.com
Thu Sep 3 20:29:43 CEST 2009
Hello,
I am trying to find the best way to do this. My goal is to only call this subroutine only ONCE, and the logic is contingent upon two outputs.
lWords=[...] # List of many, many words
lData=[...] #list of some words that need to be validated against lWords
#subroutine to search for words, ignore case
def sub1(foo):
pFoo=re.compile(foo,re.I)
for word in lWords:
if re.search(pFoo,word):
return[1,word]
#logic loop
for word in lData:
if word in lWords:
continue
elif sub1(word)[0]=1:
word=sub1(word)[1] # <--- Here is my question.
else:
print word " not found.\n"
The subroutine is being run once at the elif statement. I don't want to run it again just to get the [1] value.
*Is there any way to capture all of the values returned when it is run during the elif statement?
*Is this actually running twice?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090903/be2c0dfb/attachment.htm>
More information about the Tutor
mailing list