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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -