Should yield be used in list comprehension in Scrapy
Question: I'm writing a spider. And in that spider I need to yield requests, with
different params. It is something like,

    
    
    for i in xrange(0, len(products), k):
        some_ids = ','.join([a_product['id'] for a_product in products[i: i + k]])
        for a_condition in ['c1', 'c2', 'c3']:
            yield CustomRequest(url='api:endpoint',
                                params=dict(Condition=a_condition,
                                            param1='val1',
                                            param2=some_ids,
                                           )
                               )
    

Is there more pythonic way to do this?


Answer: > Is there more pythonic way to do this?

it's kind of vague question, it depends what you're trying to accomplish, it's
difficult to tell how rest of your code looks like. In general [generators are
great](http://stackoverflow.com/questions/231767/what-does-the-yield-keyword-
do-in-python/231855#231855) so you should use them if you can. They are
definitely 'Pythonic' but your top priority should probably be having clean,
efficient and working code, adhering to idioms of language is not most
important thing IMO.

