fp/lambda question

Duncan Booth duncan at NOSPAMrcp.co.uk
Mon Apr 15 07:04:31 EDT 2002


"Jozef" <jozef at jozef.joz> wrote in news:a9a7sa$qd3$1 at reader05.wxs.nl:

>> def relatively_prime(a, b): return gcd(a, b) == 1
> 
> Thats funny, I wanted to do that but I don't know how to use filter
> with a function that takes 2 variables. E.g., to get a list if all
> numbers less than 10 relatively prime to 3, I would write
> 
>      filter(relatively_prime, range(1, 10)) # aaah, where does the 3
>      go??? 
> 
If you want this readable then use a list comprehension:
   [ n for n in range(1,10) if relatively_prime(n, 3) ]

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list