f | def function_that_says_ni(*args, **kwargs): | f | def function_that_says_ni(*args, **kwargs): |
| # Define constants | | # Define constants |
| SHRUB_DEFINITIONS = ("храст", "shrub", "bush") | | SHRUB_DEFINITIONS = ("храст", "shrub", "bush") |
| MAX_COST = 42 | | MAX_COST = 42 |
| # Init variables | | # Init variables |
| cost = 0 | | cost = 0 |
| niceness_unique_vals = set() | | niceness_unique_vals = set() |
| # Get list of tuples of all input arguments combined | | # Get list of tuples of all input arguments combined |
| arg_list = list(map(lambda x: ('', x), args)) + list(kwargs.items()) | | arg_list = list(map(lambda x: ('', x), args)) + list(kwargs.items()) |
| # Collect cost and unique name characters | | # Collect cost and unique name characters |
| for name, val in arg_list: | | for name, val in arg_list: |
| if type(val) is not dict: | | if type(val) is not dict: |
| continue | | continue |
t | if val.get('name', '') in SHRUB_DEFINITIONS: | t | if val.get('name', '').lower() in SHRUB_DEFINITIONS: |
| cost += val.get('cost', 0) | | cost += val.get('cost', 0) |
| niceness_unique_vals.update(*name) | | niceness_unique_vals.update(*name) |
| # Determine cost and niceness and return the result | | # Determine cost and niceness and return the result |
| if int(cost) and cost <= MAX_COST: | | if int(cost) and cost <= MAX_COST: |
| if len(niceness_unique_vals) % int(cost) == 0: | | if len(niceness_unique_vals) % int(cost) == 0: |
| return f"{cost:.2f}лв" | | return f"{cost:.2f}лв" |
| return "Ni!" | | return "Ni!" |
16.10.2024 12:55