g = lambda x: x * 2 # create lambda function, x is the argument and returns x * 2 print g(5) # prints 5*2 = 10 # Compute prime numbers with lambda nums = range(2, 100) # primes start at 2 for i in range(2, 8): # loop over all possible divisors # Leave the element in the list if it is equal to i, # or if it leaves a non-zero remainder when divided by i. # Otherwise remove it from the list. nums = filter(lambda x: x == i or x % i, nums) print nums
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question