-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamel.py
23 lines (18 loc) · 897 Bytes
/
camel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def main():
user_input = input('camelCase: ') # removes every whitespace in between string
print(camel_to_snake_case(user_input)) # camel_to_snake_case function call
def camel_to_snake_case(camelCaseString):
# removes any space(s) in between with leading/trailing space(s) & "_"
camelCaseString = camelCaseString.replace('_', '').strip(' ').replace(' ', '')
if (any(char.isalpha() for char in camelCaseString)) and (any(char.isdigit() for char in camelCaseString)) :
return camelCaseString
else:
for char in camelCaseString:
if camelCaseString.__contains__(char.upper()):
camelCaseString = camelCaseString.replace(char.upper(), f'_{char.lower()}')
camelCaseString = camelCaseString.lstrip('_')
else:
camelCaseString
return camelCaseString
if __name__ == '__main__':
main()