On 11/03/2011 12:37 PM, lina wrote:
<snip>
I have another question, regarding the generator,
def translate_process(dictionary,tobetranslatedfile):
results=[]
with open(tobetranslatedfile,"r") as f:
results=(dictionary[line.split()[2]] for line in f)
print(list(results))
print(len(list(results)))
Here the print(list(results))
did print a long list out,
but why later print(len(list(results)))
print 0 out?
sorry, seems that way is very trivial.
Best regards,
_
resuts is a generator, and they can only be iterated through once. So
if you need it more than once, convert it to a list first, and save that
list. or just use a list comprehension in the first place, (just change
the parenthese to square brackets)
--
DaveA
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor