Examples :
Input: GeeksForGeeks Output: geeks_for_geeks Input: ThisIsInCamelCase Output: this_is_in_camel_case
Let’s see how we can accomplish this task.
Method # 1: Naive approach
This is a naive implementation for converting camel craft into snake craft. First, we initialize the res variable with an empty list and add the first (lowercase) character to it. Now, every time we come across an uppercase alphabet, we add & # 39; _ & # 39; and the alphabet (lowercase) to & # 39; res & # 39;, otherwise just add the alphabet only.
|
Exit :
geeks_for_geeks
Method # 2: Understanding the List
|
Exit:
geeks_for_geek s
Method # 3: Python Reduce ()
The Python Reduce () method applies function to all string alphabets, wherever it finds capital letters, it adds "_" in front of it and replaces capital letters with lowercase ones.
|
Exit:
geeks_for_geeks
Method # 4: Python Regex
|
Exit:
geeks_for_geeks