- BASICS
- Statements
- Operators
- Functions
- Incremental
- Errors
- FUNCTIONS
- Recursion
- Objects
-
Lambda
- STRINGS
- Immutable
- Raw Strings
- Validation
- Config
- Security
- CLASS
- Definition
- Attributes
- Functional
- Methods
- COLLECTIONS
- Lists
- Dictionaries
- Efficiency
- Tree
- Iterator
- Tuples
- References
- STORAGE
- Files
- Databases
- Pipes
- With Open
- Shelve
- Zip
- Csv
- Json
Lambda
""" Lambda (or anonymous) functions are used for writing single statement
The result of a lambda function is the return value
It is often less typing (and clearer) to pass a lamda function ...
as opposed to a function
"""
def h(x):
return x*2
print(h(2))
h = lambda x: x*2
print(h(3))
# Usage example: Sort by the number of distinc letters
S = ['foo', 'card', 'bar', 'aaaa']
S.sort(key=lambda x: len(set(x)))
print(S)
Last update: 203 days ago