10 examples of 'convert a string to camel case in python' in Python

Every line of 'convert a string to camel case in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
92def to_camel_case(string):
93 """Give the camelCase representation of a snake_case string."""
94 return re.sub(r"_(\w)", lambda x: x.group(1).upper(), string)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

118def to_camel_case(s):
119 return re.sub(KEYS_CAMELCASE_PATTERN, lambda x: x.group(1).upper(), s)
33def to_camel_case(name):
34 if type(name) == bytes:
35 name = name.decode()
36 components = name.split('_')
37 return "".join(x.title() for x in components)
98def to_camel_case(s):
99 new_s = ''.join(x.capitalize() or '_' for x in s.split('_'))
100 lower_first_letter = lambda s: s[:1].lower() + s[1:] if s else ''
101 return lower_first_letter(new_s)
28def to_camel_case(value):
29 """
30 Convert the given string to camel case
31 :param value: string
32 :return: string
33 """
34 content = value.split('_')
35 return content[0] + ''.join(word.title() for word in content[1:] if not word.isspace())
6def to_camel_case(snake_str):
7 components = snake_str.split('_')
8 # We capitalize the first letter of each component except the first one
9 # with the 'title' method and join them together.
10 return components[0] + "".join(x.title() if x else '_'
11 for x in components[1:])
31def to_camel_case(name):
32 """Convert string to CamelCase"""
33 # These two objects should remain untouched
34 if name == 'system':
35 return 'System'
36 elif name == 'audio_player':
37 return 'AudioPlayer'
38 for match in re.finditer('(_)([a-z])', name):
39 underscore, letter = match.group(0)
40 name = list(name)
41 name[match.start()+1] = letter.upper()
42 return ''.join([n for n in name if n != '_'])
9def toCamelCase(s):
10 if s == '': return ''
11 return string.lower(s[0]) + s[1:]
52def to_camel_case(snake_str: str) -> str:
53 """Convert snake_case to camelCase.
54
55 Capitalize the first letter of each part except the first one
56 with the `capitalize` method and join all the parts together.
57
58 Adapted from this response in StackOverflow
59 http://stackoverflow.com/a/19053800/1072990
60
61 :param snake_str:
62 :return:
63 """
64 parts = snake_str.split("_")
65 return parts[0] + "".join(x.capitalize() if x else "_" for x in parts[1:])
6def camel_to_snake(name):
7 s1 = first_cap_re.sub(r'\1_\2', name)
8 return all_cap_re.sub(r'\1_\2', s1).lower()

Related snippets