I'm often confused by recent obsession of generators in python. I'll try to explain them as simply as possible. Say you have never used iterators but coded in python. BUT I'm sure you have used dictionaries ( dict ) and have met requirement to iterate through it's keys and/or values. TADA! You have used generators already ;). So generator is a function in python. Except for it uses a keyword yield in it's code. Thus making it the iterator. So you could call this function in a sequence like you would probably do iterating over a dictionary already. E.g.: # typical iteration through dictionary key: value set for key, value in dict .iteritems(): # do someth # Usage of your own iterator for item in iterator_functuon(): # do something with function generated output So this function returns an iterator generator like the dict() type has by default. And has a next() function, like usual iterators have. So in attempt t...
My thoughts/recipes on Django, Python, JS and other things I try...