TelenkovDmitry 3 năm trước cách đây
commit
7f098bf966
1 tập tin đã thay đổi với 50 bổ sung0 xóa
  1. 50 0
      py_task.py

+ 50 - 0
py_task.py

@@ -0,0 +1,50 @@
+# 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).
+
+#Examples
+
+#"the-stealth-warrior" gets converted to "theStealthWarrior"
+#"The_Stealth_Warrior" gets converted to "TheStealthWarrior"
+
+def to_camel_case(s):
+    return s[0] + s.title().translate(None, "-_")[1:] if s else s
+
+
+def to_camel_case(text):
+    removed = text.replace('-', ' ').replace('_', ' ').split()
+    if len(removed) == 0:
+        return ''
+    return removed[0]+ ''.join([x.capitalize() for x in removed[1:]])
+
+
+def to_camel_case(text):
+    return text[:1] + text.title()[1:].replace('_', '').replace('-', '')
+
+
+import re
+def to_camel_case(text):
+    return re.sub('[_-](.)', lambda x: x.group(1).upper(), text)
+
+
+def to_camel_case(text):
+    words = text.replace('_', '-').split('-')
+    return words[0] + ''.join([x.title() for x in words[1:]])
+
+
+def to_camel_case(text):
+    cap = False
+    newText = ''
+    for t in text:
+        if t == '_' or t == '-':
+            cap = True
+            continue
+        else:
+            if cap == True:
+                t = t.upper()
+            newText = newText + t
+            cap = False
+    return newText
+
+
+def to_camel_case(text):
+    return "".join([i if n==0 else i.capitalize() for n,i in enumerate(text.replace("-","_").split("_"))])
+