Hướng dẫn how to separate capital letters in python - cách tách chữ in hoa trong python

Thay thế mọi chữ cái chữ hoa 'l' trong không gian trống cộng với chữ cái đó "L". Chúng ta có thể làm điều này bằng cách sử dụng danh sách hiểu hoặc chúng ta có thể xác định một chức năng để thực hiện nó như sau.

Show
    s = 'TheLongANDWindingRoad ABC A123B45'
    ''.join([char if (char.islower() or not char.isalpha()) else ' '+char for char in list(s)]).strip().split()
    >>> ['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road', 'A', 'B', 'C', 'A123', 'B45']
    

    Nếu bạn chọn đi theo một chức năng, đây là làm thế nào.

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    

    Trong trường hợp của ví dụ đã cho:

    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    

    Nhưng hầu hết thời gian chúng tôi đang chia một câu ở các chữ cái trên, thường là trường hợp chúng tôi muốn duy trì các chữ viết tắt thường là một dòng chữ in hoa liên tục. Mã dưới đây sẽ giúp.

    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    

    Thanks.

    Cải thiện bài viết

    Lưu bài viết

    Đưa ra một chuỗi, hãy viết một chương trình Python để phân chia chuỗi trên các ký tự chữ hoa. Hãy để thảo luận về một vài phương pháp để giải quyết vấn đề.

    Phương thức số 1: Sử dụng re.findall () phương thức & nbsp; 

    Python3

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    0
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    1

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    2
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    4

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    7
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    8

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    9
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    1

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    9
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    4
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    8

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    9
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    0
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    1
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    2

    Output:

    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']

    Phương pháp số 2: Sử dụng Re.Split ()

    Python3

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    0
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    1

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    2
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    4

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    7
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    8

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    9
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    1

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    9
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    0
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    1
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    2

    Output:

    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    9
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    4
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    8
     

    Python3

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    2
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    4

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    7
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    8

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    9
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    1

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    9
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    4
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    8

    Phương pháp số 2: Sử dụng Re.Split ()

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    9
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    0
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    1
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    2

    Output:

    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    9
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    4
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    5
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    6
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    7
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    8__

    Python3

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    2
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    4

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    7
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    8

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    09
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    11

    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    13
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    7
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    15

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    16
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    1
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    18

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    19
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    09
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    4
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    23
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    4
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    25

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    16
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    27
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    28

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    19
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    09
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    4
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    25

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    34
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    36
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    23
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    38

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    39

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    9
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    0
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    1
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    45

    Đầu ra

    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']

    Cải thiện bài viết

    Python3

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    2
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    4

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    7
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    8

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    09
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    11

    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    13
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    7
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    15

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    16
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    1
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    13
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    7
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    20

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    19
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    09
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    4
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    23
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    4
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    25

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    16
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    27
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    28

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    19
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    09
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    4
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    25

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    34
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    36
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    23
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    38

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    39

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    9
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    0
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    1
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    45

    Đầu ra

    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']

    Cải thiện bài viết

    Python3

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    2
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    4

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    7
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    8

    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    06
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    08

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    09
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    11

    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    13
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    7
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    15

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    16
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    1
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    13
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    7
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    20

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    19
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    09
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    4
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    23
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    4
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    25

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    16
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    27
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    28

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    19
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    09
    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']
    4
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    25

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    34
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    3
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    36
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    23
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    38

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    39

    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    5
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    6
    print(splitAtUpperCase('TheLongAndWindingRoad')) 
    >>>['The', 'Long', 'A', 'N', 'D', 'Winding', 'Road']
    
    9
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    0
    def splitAtUpperCase(s):
        for i in range(len(s)-1)[::-1]:
            if s[i].isupper() and s[i+1].islower():
                s = s[:i]+' '+s[i:]
            if s[i].isupper() and s[i-1].islower():
                s = s[:i]+' '+s[i:]
        return s.split()
    
    splitAtUpperCase('TheLongANDWindingRoad')
    
    >>> ['The', 'Long', 'AND', 'Winding', 'Road']
    
    1
    def splitAtUpperCase(text):
        result = ""
        for char in text:
            if char.isupper():
                result += " " + char
            else:
                result += char
        return result.split()
    
    45

    Đầu ra

    Initial String GeeksForGeeks
    Resultant prefix ['Geeks', 'For', 'Geeks']