Advanced Topics in Python_Lambda Syntax


#1

Error:
Traceback (most recent call last):
File "python", line 2, in
File "python", line 2, in
TypeError: not all arguments converted during string formatting

code:
languages = ["HTML", "JavaScript", "Python", "Ruby"]
print filter(lambda x: x % 3 == 2,languages)


#2

here:

print filter(lambda x: x % 3 == 2,languages)

why do yo uuse the modulo operator? You need to check if x equals Python, you don't need the modulo operator for this


#3

yabro didshitcompleteshit


#4

what is x here? is it the index or the value?


#5

x are values from the language list


#6

Are you sure? and can we just use any alphabet x,y,z etc?


#7

yea, we can.

lambda's are one line function, x is the function parameter:

lambda x:
def example(x):

we can use any valid variable name for lambda, just like we can use any valid variable name for function parameter


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.