You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above solution is correcct and nicely structures it does exactly what the problem asks.
49
+
50
+
51
+
but we can make some refinments as well.
52
+
53
+
=> Efficiency: String concatenation (result += ...) in a loop is less efficient in Python because strings are immutable. A common
54
+
pattern is to collect pieces in a list and ".join() at the end:
55
+
=> The below soltuion is functionally identical, but faster for long strings.
56
+
=> Simplification: You could avoid storing both uppercase and lowercase vowels by just checking char.lower()
57
+
The above solution is correct but the only improvement is performance (using a list instead of repeated string concatenation) and possibly simplifying the vowel check.
58
+
Otherwise, it's spot-on.
59
+
"""
60
+
61
+
defvowel_case(s: str) ->str:
62
+
vowels="aeiou"
63
+
result= []
64
+
forchins:
65
+
ifch.isalpha():
66
+
ifch.lower() invowels:
67
+
result.append(ch.upper())
68
+
else:
69
+
result.append(ch.lower())
70
+
else:
71
+
result.append(ch)
72
+
73
+
return"".join(result)
74
+
75
+
"""
76
+
=> ch.isalpha() in Python ensures we only transform letters.
77
+
=> in Javascript, /[a-zA-Z]/.test(ch) checks if the character is alphabetic.
0 commit comments