Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

deprecated_lambda.py 722B

1234567891011121314151617181920212223
  1. # pylint: disable=missing-docstring,invalid-name,no-absolute-import
  2. import functools
  3. # Don't do this, use a comprehension instead.
  4. assert map(lambda x: x*2, [1, 2, 3]) == [2, 4, 6] # [deprecated-lambda]
  5. assert filter(lambda x: x != 1, [1, 2, 3]) == [2, 3] # [deprecated-lambda]
  6. # It's still ok to use map and filter with anything but an inline lambda.
  7. double = lambda x: x * 2
  8. assert map(double, [1, 2, 3]) == [2, 4, 6]
  9. # It's also ok to pass lambdas to other functions.
  10. assert functools.reduce(lambda x, y: x * y, [1, 2, 3, 4]) == 24
  11. # Or to a undefined function or one with varargs
  12. def f(*a):
  13. return len(a)
  14. f(lambda x, y: x + y, [1, 2, 3])
  15. undefined_function(lambda: 2) # pylint: disable=undefined-variable