I am new python programmer,what I have understood so far,”yield” keyword returns an object in lieu of that the generator function returns only the generator object.
so if I have a list which contains 10K items,how I can make smart,pythonic solution without appending values in a list and make it large.
That means,I am appending some values to a list and finally a large list is created like below:
def example():
final_list = []
for i in range(0,10000):
final_list.append(i)
return final_list
This is just an example,not a real problem,I used range() just for generating loop nothing else,in my real problem,there are no sequential data,it will be random strings,and the findla list will contain 10K string.
so how can I get all the values without appending to a list in an efficient pythonic manner.
Thanks.
You said:
So:
When you call
oneStringAtATime(), it sets up the generator function calledcrawler(); each timecrawler()executesyield, the loop inoneStringAtATime()iterates once with that string. Whencrawler()runs out of web pages and exits the function, theoneStringAtATime()loop exits.