1"""Just a bit different of a solution, nothing too fancy."""
2
3
4VALID_SHRUBS = ('храст', 'shrub', 'bush')
5MAX_COST = 42
6
7
8def function_that_says_ni(*args, **kwargs):
9 # Get all pairs as key-value pairs (tuples) with empty "keys" for positional args
10 all_arg_pairs = [('', arg) for arg in args] + list(kwargs.items())
11 # Filter only dicts that contain shrubs, bushes, etc.
12 shrub_pairs = [pair for pair in all_arg_pairs
13 if isinstance(pair[1], dict)
14 and pair[1].get('name', 'шак шак шука, дюнера е тука').lower() in VALID_SHRUBS]
15 # The following is pretty self-explanatory
16 total_unique_chars = len(set(''.join(shrub_pair[0] for shrub_pair in shrub_pairs)))
17 total_cost = sum(shrub_pair[1].get('cost', 0) for shrub_pair in shrub_pairs)
18 total_cost_whole_part = int(total_cost)
19 # Determine if the shrubbery is satisfactory
20 if (total_cost <= MAX_COST # Ensure it's not too expensive
21 and total_cost_whole_part # Protect from division by 0
22 and not total_unique_chars % total_cost_whole_part): # Ensure it's pretty
23 return f'{total_cost:.2f}лв'
24 return 'Ni!'
..........
----------------------------------------------------------------------
Ran 10 tests in 0.000s
OK
t | 1 | """Just a bit different solution, nothing too fancy.""" | t | 1 | """Just a bit different of a solution, nothing too fancy.""" |
2 | 2 | ||||
3 | 3 | ||||
4 | VALID_SHRUBS = ('храст', 'shrub', 'bush') | 4 | VALID_SHRUBS = ('храст', 'shrub', 'bush') | ||
5 | MAX_COST = 42 | 5 | MAX_COST = 42 | ||
6 | 6 | ||||
7 | 7 | ||||
8 | def function_that_says_ni(*args, **kwargs): | 8 | def function_that_says_ni(*args, **kwargs): | ||
9 | # Get all pairs as key-value pairs (tuples) with empty "keys" for positional args | 9 | # Get all pairs as key-value pairs (tuples) with empty "keys" for positional args | ||
10 | all_arg_pairs = [('', arg) for arg in args] + list(kwargs.items()) | 10 | all_arg_pairs = [('', arg) for arg in args] + list(kwargs.items()) | ||
11 | # Filter only dicts that contain shrubs, bushes, etc. | 11 | # Filter only dicts that contain shrubs, bushes, etc. | ||
12 | shrub_pairs = [pair for pair in all_arg_pairs | 12 | shrub_pairs = [pair for pair in all_arg_pairs | ||
13 | if isinstance(pair[1], dict) | 13 | if isinstance(pair[1], dict) | ||
14 | and pair[1].get('name', 'шак шак шука, дюнера е тука').lower() in VALID_SHRUBS] | 14 | and pair[1].get('name', 'шак шак шука, дюнера е тука').lower() in VALID_SHRUBS] | ||
15 | # The following is pretty self-explanatory | 15 | # The following is pretty self-explanatory | ||
16 | total_unique_chars = len(set(''.join(shrub_pair[0] for shrub_pair in shrub_pairs))) | 16 | total_unique_chars = len(set(''.join(shrub_pair[0] for shrub_pair in shrub_pairs))) | ||
17 | total_cost = sum(shrub_pair[1].get('cost', 0) for shrub_pair in shrub_pairs) | 17 | total_cost = sum(shrub_pair[1].get('cost', 0) for shrub_pair in shrub_pairs) | ||
18 | total_cost_whole_part = int(total_cost) | 18 | total_cost_whole_part = int(total_cost) | ||
19 | # Determine if the shrubbery is satisfactory | 19 | # Determine if the shrubbery is satisfactory | ||
20 | if (total_cost <= MAX_COST # Ensure it's not too expensive | 20 | if (total_cost <= MAX_COST # Ensure it's not too expensive | ||
21 | and total_cost_whole_part # Protect from division by 0 | 21 | and total_cost_whole_part # Protect from division by 0 | ||
22 | and not total_unique_chars % total_cost_whole_part): # Ensure it's pretty | 22 | and not total_unique_chars % total_cost_whole_part): # Ensure it's pretty | ||
23 | return f'{total_cost:.2f}лв' | 23 | return f'{total_cost:.2f}лв' | ||
24 | return 'Ni!' | 24 | return 'Ni!' |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | """Just a bit different solution, nothing too fancy.""" | f | 1 | """Just a bit different solution, nothing too fancy.""" |
n | n | 2 | |||
2 | 3 | ||||
3 | VALID_SHRUBS = ('храст', 'shrub', 'bush') | 4 | VALID_SHRUBS = ('храст', 'shrub', 'bush') | ||
4 | MAX_COST = 42 | 5 | MAX_COST = 42 | ||
t | t | 6 | |||
5 | 7 | ||||
6 | def function_that_says_ni(*args, **kwargs): | 8 | def function_that_says_ni(*args, **kwargs): | ||
7 | # Get all pairs as key-value pairs (tuples) with empty "keys" for positional args | 9 | # Get all pairs as key-value pairs (tuples) with empty "keys" for positional args | ||
8 | all_arg_pairs = [('', arg) for arg in args] + list(kwargs.items()) | 10 | all_arg_pairs = [('', arg) for arg in args] + list(kwargs.items()) | ||
9 | # Filter only dicts that contain shrubs, bushes, etc. | 11 | # Filter only dicts that contain shrubs, bushes, etc. | ||
10 | shrub_pairs = [pair for pair in all_arg_pairs | 12 | shrub_pairs = [pair for pair in all_arg_pairs | ||
11 | if isinstance(pair[1], dict) | 13 | if isinstance(pair[1], dict) | ||
12 | and pair[1].get('name', 'шак шак шука, дюнера е тука').lower() in VALID_SHRUBS] | 14 | and pair[1].get('name', 'шак шак шука, дюнера е тука').lower() in VALID_SHRUBS] | ||
13 | # The following is pretty self-explanatory | 15 | # The following is pretty self-explanatory | ||
14 | total_unique_chars = len(set(''.join(shrub_pair[0] for shrub_pair in shrub_pairs))) | 16 | total_unique_chars = len(set(''.join(shrub_pair[0] for shrub_pair in shrub_pairs))) | ||
15 | total_cost = sum(shrub_pair[1].get('cost', 0) for shrub_pair in shrub_pairs) | 17 | total_cost = sum(shrub_pair[1].get('cost', 0) for shrub_pair in shrub_pairs) | ||
16 | total_cost_whole_part = int(total_cost) | 18 | total_cost_whole_part = int(total_cost) | ||
17 | # Determine if the shrubbery is satisfactory | 19 | # Determine if the shrubbery is satisfactory | ||
18 | if (total_cost <= MAX_COST # Ensure it's not too expensive | 20 | if (total_cost <= MAX_COST # Ensure it's not too expensive | ||
19 | and total_cost_whole_part # Protect from division by 0 | 21 | and total_cost_whole_part # Protect from division by 0 | ||
20 | and not total_unique_chars % total_cost_whole_part): # Ensure it's pretty | 22 | and not total_unique_chars % total_cost_whole_part): # Ensure it's pretty | ||
21 | return f'{total_cost:.2f}лв' | 23 | return f'{total_cost:.2f}лв' | ||
22 | return 'Ni!' | 24 | return 'Ni!' |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
19.10.2024 18:24