python - Two conditions in single line for loop -


i have function has return statement follows:

x = 0 return{     'restaurantlist' : [restaurant.serializegeneral(myarray[x]) restaurant in self.restaurantlist],     'success' : self.success     } 

i need increment x every time for loop runs, however, can't seem syntax right.

you can use enumerate function both index , value each restaurant in list follows:

return {     'restaurantlist' : [restaurant.serializegeneral(myarray[x]) x, restaurant in enumerate(self.restaurantlist)],     'success' : self.success } 

you should compute list outside of list comprehension because line way long readable.


Comments