py_task.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # 1. Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized only if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case).
  2. #Examples
  3. #"the-stealth-warrior" gets converted to "theStealthWarrior"
  4. #"The_Stealth_Warrior" gets converted to "TheStealthWarrior"
  5. def to_camel_case(s):
  6. return s[0] + s.title().translate(None, "-_")[1:] if s else s
  7. def to_camel_case(text):
  8. removed = text.replace('-', ' ').replace('_', ' ').split()
  9. if len(removed) == 0:
  10. return ''
  11. return removed[0]+ ''.join([x.capitalize() for x in removed[1:]])
  12. def to_camel_case(text):
  13. return text[:1] + text.title()[1:].replace('_', '').replace('-', '')
  14. import re
  15. def to_camel_case(text):
  16. return re.sub('[_-](.)', lambda x: x.group(1).upper(), text)
  17. def to_camel_case(text):
  18. words = text.replace('_', '-').split('-')
  19. return words[0] + ''.join([x.title() for x in words[1:]])
  20. def to_camel_case(text):
  21. cap = False
  22. newText = ''
  23. for t in text:
  24. if t == '_' or t == '-':
  25. cap = True
  26. continue
  27. else:
  28. if cap == True:
  29. t = t.upper()
  30. newText = newText + t
  31. cap = False
  32. return newText
  33. def to_camel_case(text):
  34. return "".join([i if n==0 else i.capitalize() for n,i in enumerate(text.replace("-","_").split("_"))])