def to_camel_case(text: str): split_chars = "-_" # loop over each character above for split_char in split_chars: split_parts = text.split(split_char) if len(split_parts) > 1: # join titlecased parts and overwrite the text variable for the next loop text = split_parts[0] + "".join(map(lambda s: s.title(), split_parts[1:])) return text
- def to_camel_case(text: str):
- split_chars = "-_"
- # loop over each character above
- for split_char in split_chars:
- split_parts = text.split(split_char)
# skip if there was nothing to split onif len(split_parts) == 1:continueparts = []# break up the string in to it's partsfor i, item in enumerate(split_parts):# save the first part but don't change the case of the first letterif i == 0:parts.append(item)continueparts.append(f"{item[0].upper()}{item[1:]}")# join the parts and overwrite the text variable for the next looptext = "".join(parts)- if len(split_parts) > 1:
- # join titlecased parts and overwrite the text variable for the next loop
- text = split_parts[0] + "".join(map(lambda s: s.title(), split_parts[1:]))
- return text
test.describe("Testing function to_camel_case") test.it("Basic tests") test.assert_equals(to_camel_case(''), '', "An empty string was provided but not returned") test.assert_equals(to_camel_case("-"), "", "to_camel_case('-') did not return correct value") test.assert_equals(to_camel_case("_"), "", "to_camel_case('_') did not return correct value") test.assert_equals(to_camel_case("_-"), "", "to_camel_case('_-') did not return correct value") test.assert_equals(to_camel_case("-_"), "", "to_camel_case('-_') did not return correct value") test.assert_equals(to_camel_case("the_stealth_warrior"), "theStealthWarrior", "to_camel_case('the_stealth_warrior') did not return correct value") test.assert_equals(to_camel_case("The-Stealth-Warrior"), "TheStealthWarrior", "to_camel_case('The-Stealth-Warrior') did not return correct value") test.assert_equals(to_camel_case("A-B-C"), "ABC", "to_camel_case('A-B-C') did not return correct value")
- test.describe("Testing function to_camel_case")
- test.it("Basic tests")
- test.assert_equals(to_camel_case(''), '', "An empty string was provided but not returned")
- test.assert_equals(to_camel_case("-"), "", "to_camel_case('-') did not return correct value")
- test.assert_equals(to_camel_case("_"), "", "to_camel_case('_') did not return correct value")
- test.assert_equals(to_camel_case("_-"), "", "to_camel_case('_-') did not return correct value")
- test.assert_equals(to_camel_case("-_"), "", "to_camel_case('-_') did not return correct value")
- test.assert_equals(to_camel_case("the_stealth_warrior"), "theStealthWarrior", "to_camel_case('the_stealth_warrior') did not return correct value")
- test.assert_equals(to_camel_case("The-Stealth-Warrior"), "TheStealthWarrior", "to_camel_case('The-Stealth-Warrior') did not return correct value")
- test.assert_equals(to_camel_case("A-B-C"), "ABC", "to_camel_case('A-B-C') did not return correct value")
def remove(lst, excluded): excluded = frozenset(excluded) return list(filter(lambda x: x not in excluded, lst))
def remove(integers, values):return list(filter(lambda x: x not in values,integers))- def remove(lst, excluded):
- excluded = frozenset(excluded)
- return list(filter(lambda x: x not in excluded, lst))
@test.describe("Basic Test Cases") def basic_test_cases(): test.assert_equals(remove([], []), []) test.assert_equals(remove([1, 1, 3, 5, 7, 7, 7, 9, 10, 10], [1, 7, 9]), [3, 5, 10, 10]) test.assert_equals(remove([1, 2, 3, 4, 5], [2, 4]), [1, 3, 5]) test.assert_equals(remove([1, 2, 3, 4, 5], [2, 4, 2, 4, 4]), [1, 3, 5]) test.assert_equals(remove(["a", "b", "c", "d", "e"], ["d", "n", "a"]), ["b", "c", "e"])
- @test.describe("Basic Test Cases")
- def basic_test_cases():
- test.assert_equals(remove([], []), [])
- test.assert_equals(remove([1, 1, 3, 5, 7, 7, 7, 9, 10, 10], [1, 7, 9]), [3, 5, 10, 10])
- test.assert_equals(remove([1, 2, 3, 4, 5], [2, 4]), [1, 3, 5])
- test.assert_equals(remove([1, 2, 3, 4, 5], [2, 4, 2, 4, 4]), [1, 3, 5])
- test.assert_equals(remove(["a", "b", "c", "d", "e"], ["d", "n", "a"]), ["b", "c", "e"])