1ACCEPTED_NAMES = ['храст', 'bush', 'shrub']
2
3def is_a_valid_bush(argument):
4 if type(argument) != dict:
5 return False
6 else:
7 if not len(argument) or argument.get("name") is None:
8 return False
9 else:
10 return (lambda x: x.lower())(argument.get("name")) in ACCEPTED_NAMES
11
12def calculate_bush_price(argument):
13 return 0 if argument.get("cost") is None else argument.get("cost")
14
15def function_that_says_ni(*args, **kwargs) :
16 found_any_valid_bush = False
17 valid_bushes = list(filter(is_a_valid_bush, args))
18
19 if len(valid_bushes):
20 found_any_valid_bush = True
21
22 bushes_sum = sum(map(calculate_bush_price, valid_bushes))
23
24 letters_set= set()
25
26 for key, value in kwargs.items():
27 if not is_a_valid_bush(value):
28 continue
29 else:
30 found_any_valid_bush = True
31
32 for letter in key:
33 letters_set.add(letter)
34
35 bushes_sum += calculate_bush_price(value)
36
37 if not found_any_valid_bush or bushes_sum > 42 or int(bushes_sum) == 0 or len(letters_set) % int(bushes_sum) != 0:
38 return "Ni!"
39 else:
40 return f"{format(bushes_sum, ".2f")}лв"
..........
----------------------------------------------------------------------
Ran 10 tests in 0.001s
OK
Георги Кунчев
20.10.2024 12:08Само заради скоростта, с която адресира коментарите ми, давам бонус точка.
|
f | 1 | ACCEPTED_NAMES = ['храст', 'bush', 'shrub'] | f | 1 | ACCEPTED_NAMES = ['храст', 'bush', 'shrub'] |
2 | 2 | ||||
3 | def is_a_valid_bush(argument): | 3 | def is_a_valid_bush(argument): | ||
4 | if type(argument) != dict: | 4 | if type(argument) != dict: | ||
5 | return False | 5 | return False | ||
6 | else: | 6 | else: | ||
7 | if not len(argument) or argument.get("name") is None: | 7 | if not len(argument) or argument.get("name") is None: | ||
8 | return False | 8 | return False | ||
9 | else: | 9 | else: | ||
10 | return (lambda x: x.lower())(argument.get("name")) in ACCEPTED_NAMES | 10 | return (lambda x: x.lower())(argument.get("name")) in ACCEPTED_NAMES | ||
11 | 11 | ||||
12 | def calculate_bush_price(argument): | 12 | def calculate_bush_price(argument): | ||
13 | return 0 if argument.get("cost") is None else argument.get("cost") | 13 | return 0 if argument.get("cost") is None else argument.get("cost") | ||
14 | 14 | ||||
15 | def function_that_says_ni(*args, **kwargs) : | 15 | def function_that_says_ni(*args, **kwargs) : | ||
16 | found_any_valid_bush = False | 16 | found_any_valid_bush = False | ||
17 | valid_bushes = list(filter(is_a_valid_bush, args)) | 17 | valid_bushes = list(filter(is_a_valid_bush, args)) | ||
18 | 18 | ||||
19 | if len(valid_bushes): | 19 | if len(valid_bushes): | ||
20 | found_any_valid_bush = True | 20 | found_any_valid_bush = True | ||
21 | 21 | ||||
22 | bushes_sum = sum(map(calculate_bush_price, valid_bushes)) | 22 | bushes_sum = sum(map(calculate_bush_price, valid_bushes)) | ||
23 | 23 | ||||
n | 24 | letters_dict = {} | n | 24 | letters_set= set() |
25 | 25 | ||||
26 | for key, value in kwargs.items(): | 26 | for key, value in kwargs.items(): | ||
27 | if not is_a_valid_bush(value): | 27 | if not is_a_valid_bush(value): | ||
28 | continue | 28 | continue | ||
29 | else: | 29 | else: | ||
30 | found_any_valid_bush = True | 30 | found_any_valid_bush = True | ||
31 | 31 | ||||
n | 32 | for x in key: | n | 32 | for letter in key: |
33 | letters_dict[x] = 1 | 33 | letters_set.add(letter) | ||
34 | 34 | ||||
35 | bushes_sum += calculate_bush_price(value) | 35 | bushes_sum += calculate_bush_price(value) | ||
36 | 36 | ||||
t | 37 | if not found_any_valid_bush or bushes_sum > 42 or int(bushes_sum) == 0 or len(letters_dict) % int(bushes_sum) != 0: | t | 37 | if not found_any_valid_bush or bushes_sum > 42 or int(bushes_sum) == 0 or len(letters_set) % int(bushes_sum) != 0: |
38 | return "Ni!" | 38 | return "Ni!" | ||
39 | else: | 39 | else: | ||
40 | return f"{format(bushes_sum, ".2f")}лв" | 40 | return f"{format(bushes_sum, ".2f")}лв" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
n | 1 | accepted_names = ['храст', 'bush', 'shrub'] | n | 1 | ACCEPTED_NAMES = ['храст', 'bush', 'shrub'] |
2 | 2 | ||||
3 | def is_a_valid_bush(argument): | 3 | def is_a_valid_bush(argument): | ||
4 | if type(argument) != dict: | 4 | if type(argument) != dict: | ||
5 | return False | 5 | return False | ||
6 | else: | 6 | else: | ||
n | 7 | if not len(argument) or len(argument) != len(set(argument.keys()).intersection({"cost", "name"})): | n | 7 | if not len(argument) or argument.get("name") is None: |
8 | return False | 8 | return False | ||
9 | else: | 9 | else: | ||
n | 10 | return False if (lambda x: x.lower())(argument.get("name")) not in accepted_names else True | n | 10 | return (lambda x: x.lower())(argument.get("name")) in ACCEPTED_NAMES |
11 | 11 | ||||
n | 12 | def calculate_bush_price(argument) : | n | 12 | def calculate_bush_price(argument): |
13 | return 0 if argument.get("cost") is None else argument.get("cost") | 13 | return 0 if argument.get("cost") is None else argument.get("cost") | ||
14 | 14 | ||||
15 | def function_that_says_ni(*args, **kwargs) : | 15 | def function_that_says_ni(*args, **kwargs) : | ||
16 | found_any_valid_bush = False | 16 | found_any_valid_bush = False | ||
n | 17 | n | |||
18 | valid_bushes = list(filter(is_a_valid_bush, args)) | 17 | valid_bushes = list(filter(is_a_valid_bush, args)) | ||
19 | 18 | ||||
20 | if len(valid_bushes): | 19 | if len(valid_bushes): | ||
21 | found_any_valid_bush = True | 20 | found_any_valid_bush = True | ||
22 | 21 | ||||
23 | bushes_sum = sum(map(calculate_bush_price, valid_bushes)) | 22 | bushes_sum = sum(map(calculate_bush_price, valid_bushes)) | ||
24 | 23 | ||||
25 | letters_dict = {} | 24 | letters_dict = {} | ||
26 | 25 | ||||
27 | for key, value in kwargs.items(): | 26 | for key, value in kwargs.items(): | ||
28 | if not is_a_valid_bush(value): | 27 | if not is_a_valid_bush(value): | ||
29 | continue | 28 | continue | ||
30 | else: | 29 | else: | ||
31 | found_any_valid_bush = True | 30 | found_any_valid_bush = True | ||
32 | 31 | ||||
33 | for x in key: | 32 | for x in key: | ||
34 | letters_dict[x] = 1 | 33 | letters_dict[x] = 1 | ||
35 | 34 | ||||
36 | bushes_sum += calculate_bush_price(value) | 35 | bushes_sum += calculate_bush_price(value) | ||
37 | 36 | ||||
38 | if not found_any_valid_bush or bushes_sum > 42 or int(bushes_sum) == 0 or len(letters_dict) % int(bushes_sum) != 0: | 37 | if not found_any_valid_bush or bushes_sum > 42 or int(bushes_sum) == 0 or len(letters_dict) % int(bushes_sum) != 0: | ||
39 | return "Ni!" | 38 | return "Ni!" | ||
t | 40 | else : | t | 39 | else: |
41 | return f"{format(bushes_sum, ".2f")}лв" | 40 | return f"{format(bushes_sum, ".2f")}лв" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | accepted_names = ['храст', 'bush', 'shrub'] | f | 1 | accepted_names = ['храст', 'bush', 'shrub'] |
2 | 2 | ||||
3 | def is_a_valid_bush(argument): | 3 | def is_a_valid_bush(argument): | ||
4 | if type(argument) != dict: | 4 | if type(argument) != dict: | ||
5 | return False | 5 | return False | ||
6 | else: | 6 | else: | ||
7 | if not len(argument) or len(argument) != len(set(argument.keys()).intersection({"cost", "name"})): | 7 | if not len(argument) or len(argument) != len(set(argument.keys()).intersection({"cost", "name"})): | ||
8 | return False | 8 | return False | ||
9 | else: | 9 | else: | ||
10 | return False if (lambda x: x.lower())(argument.get("name")) not in accepted_names else True | 10 | return False if (lambda x: x.lower())(argument.get("name")) not in accepted_names else True | ||
11 | 11 | ||||
12 | def calculate_bush_price(argument) : | 12 | def calculate_bush_price(argument) : | ||
n | 13 | if argument.get("cost") is None: | n | 13 | return 0 if argument.get("cost") is None else argument.get("cost") |
14 | return 0 | ||||
15 | return argument.get("cost") | ||||
16 | 14 | ||||
17 | def function_that_says_ni(*args, **kwargs) : | 15 | def function_that_says_ni(*args, **kwargs) : | ||
18 | found_any_valid_bush = False | 16 | found_any_valid_bush = False | ||
19 | 17 | ||||
20 | valid_bushes = list(filter(is_a_valid_bush, args)) | 18 | valid_bushes = list(filter(is_a_valid_bush, args)) | ||
21 | 19 | ||||
22 | if len(valid_bushes): | 20 | if len(valid_bushes): | ||
23 | found_any_valid_bush = True | 21 | found_any_valid_bush = True | ||
24 | 22 | ||||
25 | bushes_sum = sum(map(calculate_bush_price, valid_bushes)) | 23 | bushes_sum = sum(map(calculate_bush_price, valid_bushes)) | ||
26 | 24 | ||||
27 | letters_dict = {} | 25 | letters_dict = {} | ||
28 | 26 | ||||
29 | for key, value in kwargs.items(): | 27 | for key, value in kwargs.items(): | ||
30 | if not is_a_valid_bush(value): | 28 | if not is_a_valid_bush(value): | ||
31 | continue | 29 | continue | ||
32 | else: | 30 | else: | ||
33 | found_any_valid_bush = True | 31 | found_any_valid_bush = True | ||
34 | 32 | ||||
35 | for x in key: | 33 | for x in key: | ||
36 | letters_dict[x] = 1 | 34 | letters_dict[x] = 1 | ||
37 | 35 | ||||
38 | bushes_sum += calculate_bush_price(value) | 36 | bushes_sum += calculate_bush_price(value) | ||
39 | 37 | ||||
40 | if not found_any_valid_bush or bushes_sum > 42 or int(bushes_sum) == 0 or len(letters_dict) % int(bushes_sum) != 0: | 38 | if not found_any_valid_bush or bushes_sum > 42 or int(bushes_sum) == 0 or len(letters_dict) % int(bushes_sum) != 0: | ||
41 | return "Ni!" | 39 | return "Ni!" | ||
42 | else : | 40 | else : | ||
t | 43 | return f"{format(bushes_sum, ".2f")}лв." | t | 41 | return f"{format(bushes_sum, ".2f")}лв" |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|