python - How to implement this using map and filter? -


how write statement using map , filter same result list comprehension expression:

[(x,y) x in range(10) if x%5==0  y in range(10) if y%5==1] 

result:

[(0, 1), (0, 6), (5, 1), (5, 6)] 

i know seems pointless, i'm curious

this how did without comprehesions:

sum(map(lambda x: map(lambda y: (x,y), filter(lambda y: y%5==1,range(10))), filter(lambda x: x%5==0,range(10))),[]) 

executing:

>>> sum(map(lambda x: map(lambda y: (x,y), filter(lambda y: y%5==1,range(10))), filter(lambda x: x%5==0,range(10))),[]) [(0, 1), (0, 6), (5, 1), (5, 6)] 

the last, , (maybe)nasty trick using sum flatten list. getting [[(0, 1), (0, 6)], [(5, 1), (5, 6)]].


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -