Repository: TheAlgorithms/Python
Pull request: Convert snake_case to camelCase or PascalCase (#7028)
### Describe your change:

Fixes #7028 

* [X] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [ ] Documentation change?

### Checklist:
* [X] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
* [X] This pull request is all my own work -- I have not plagiarized.
* [X] I know that pull requests will not be merged if they fail the automated tests.
* [X] This PR only changes one algorithm file.  To ease review, please open separate PRs for separate algorithms.
* [X] All new Python files are placed inside an existing directory.
* [X] All filenames are in all lowercase characters with no spaces or dashes.
* [X] All functions and variable names follow Python naming conventions.
* [X] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html).
* [X] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing.
* [X] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
* [X] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.


Problem statement:
Convert snake_case to camelCase or PascalCase
### Feature description

An algorithm that given a string formatted as snake_case returns it as camelCase or PascalCase depending on Boolean parameter.

Examples:

`def snake_to_camel_case(input: str, use_pascal: bool = False) -> str`
`snake_to_camel_case('some_string_in_snake_case') -> 'someStringInSnakeCase'`
`snake_to_camel_case('some_string_in_snake_case', True) -> 'SomeStringInSnakeCase'`

### Would you like to work on this feature?

- [X] Yes, I want to work on this feature!

Hints from issue discussion:
Please assign it to me, I have almost finished it

Commit message: Added snake_case to Camel or Pascal case Fixes: #7028

Patch to review:
diff --git a/strings/snake_case_to_camel_pascal_case.py b/strings/snake_case_to_camel_pascal_case.py
new file mode 100644
index 000000000000..614cb841fd18
--- /dev/null
+++ b/strings/snake_case_to_camel_pascal_case.py
@@ -0,0 +1,58 @@
+def snake_to_camel_case(input: str, use_pascal: bool = False) -> str:
+    """
+    Transforms a snake_case fiven string to camelCase (or PascalCase if indicated)
+    (defaults to not use Pascal)
+
+    >>> snake_to_camel_case("some_random_string")
+    'someRandomString'
+
+    >>> snake_to_camel_case("some_random_string", use_pascal=True)
+    'SomeRandomString'
+
+    >>> snake_to_camel_case("some_random_string_with_numbers_123")
+    'someRandomStringWithNumbers123'
+
+    >>> snake_to_camel_case("some_random_string_with_numbers_123", use_pascal=True)
+    'SomeRandomStringWithNumbers123'
+
+    >>> snake_to_camel_case(123)
+    Traceback (most recent call last):
+        ...
+    ValueError: Expected string as input, found <class 'int'>
+
+    >>> snake_to_camel_case("some_string", use_pascal="True")
+    Traceback (most recent call last):
+        ...
+    ValueError: Expected boolean as use_pascal parameter, found <class 'str'>
+    """
+
+    if not isinstance(input, str):
+        raise ValueError(f"Expected string as input, found {type(input)}")
+    if not isinstance(use_pascal, bool):
+        raise ValueError(
+            f"Expected boolean as use_pascal parameter, found {type(use_pascal)}"
+        )
+
+    words = input.split("_")
+
+    start_index = 0 if use_pascal else 1
+
+    words_to_capitalize = words[start_index:]
+
+    capitalized_words = []
+
+    for word in words_to_capitalize:
+        capitalized_words.append(word[0].upper() + word[1:])
+
+    result = "" if use_pascal else words[0]
+
+    for word in capitalized_words:
+        result += word
+
+    return result
+
+
+if __name__ == "__main__":
+    from doctest import testmod
+
+    testmod()


Code review comments:
diff_hunk: @@ -0,0 +1,58 @@
+def snake_to_camel_case(input: str, use_pascal: bool = False) -> str:
+    """
+    Transforms a snake_case fiven string to camelCase (or PascalCase if indicated)
+    (defaults to not use Pascal)
+
+    >>> snake_to_camel_case("some_random_string")
+    'someRandomString'
+
+    >>> snake_to_camel_case("some_random_string", use_pascal=True)
+    'SomeRandomString'
+
+    >>> snake_to_camel_case("some_random_string_with_numbers_123")
+    'someRandomStringWithNumbers123'
+
+    >>> snake_to_camel_case("some_random_string_with_numbers_123", use_pascal=True)
+    'SomeRandomStringWithNumbers123'
+
+    >>> snake_to_camel_case(123)
+    Traceback (most recent call last):
+        ...
+    ValueError: Expected string as input, found <class 'int'>
+
+    >>> snake_to_camel_case("some_string", use_pascal="True")
+    Traceback (most recent call last):
+        ...
+    ValueError: Expected boolean as use_pascal parameter, found <class 'str'>
+    """
+
+    if not isinstance(input, str):
+        raise ValueError(f"Expected string as input, found {type(input)}")
+    if not isinstance(use_pascal, bool):
+        raise ValueError(
+            f"Expected boolean as use_pascal parameter, found {type(use_pascal)}"
+        )
+
+    words = input.split("_")
+
+    start_index = 0 if use_pascal else 1
+
+    words_to_capitalize = words[start_index:]
+
+    capitalized_words = []
+
+    for word in words_to_capitalize:
+        capitalized_words.append(word[0].upper() + word[1:])
path: strings/snake_case_to_camel_pascal_case.py
text: @user1:
```suggestion
    capitalized_words = [(word[0].upper() + word[1:]) for word in words_to_capitalize]
```

diff_hunk: @@ -0,0 +1,58 @@
+def snake_to_camel_case(input: str, use_pascal: bool = False) -> str:
+    """
+    Transforms a snake_case fiven string to camelCase (or PascalCase if indicated)
+    (defaults to not use Pascal)
+
+    >>> snake_to_camel_case("some_random_string")
+    'someRandomString'
+
+    >>> snake_to_camel_case("some_random_string", use_pascal=True)
+    'SomeRandomString'
+
+    >>> snake_to_camel_case("some_random_string_with_numbers_123")
+    'someRandomStringWithNumbers123'
+
+    >>> snake_to_camel_case("some_random_string_with_numbers_123", use_pascal=True)
+    'SomeRandomStringWithNumbers123'
+
+    >>> snake_to_camel_case(123)
+    Traceback (most recent call last):
+        ...
+    ValueError: Expected string as input, found <class 'int'>
+
+    >>> snake_to_camel_case("some_string", use_pascal="True")
+    Traceback (most recent call last):
+        ...
+    ValueError: Expected boolean as use_pascal parameter, found <class 'str'>
+    """
+
+    if not isinstance(input, str):
+        raise ValueError(f"Expected string as input, found {type(input)}")
+    if not isinstance(use_pascal, bool):
+        raise ValueError(
+            f"Expected boolean as use_pascal parameter, found {type(use_pascal)}"
+        )
+
+    words = input.split("_")
+
+    start_index = 0 if use_pascal else 1
+
+    words_to_capitalize = words[start_index:]
+
+    capitalized_words = []
+
+    for word in words_to_capitalize:
+        capitalized_words.append(word[0].upper() + word[1:])
+
+    result = "" if use_pascal else words[0]
+
+    for word in capitalized_words:
+        result += word
path: strings/snake_case_to_camel_pascal_case.py
text: @user1:
Here instead of adding it to a string you can just use the `"".join(...)` method

diff_hunk: @@ -0,0 +1,58 @@
+def snake_to_camel_case(input: str, use_pascal: bool = False) -> str:
+    """
+    Transforms a snake_case fiven string to camelCase (or PascalCase if indicated)
path: strings/snake_case_to_camel_pascal_case.py
text: @user1:
```suggestion
    Transforms a snake_case given string to camelCase (or PascalCase if indicated)
```