lunedì 1 febbraio 2021

Python string split camel case - version 1

myStr = "myStringInPython"


iCount = 0

pos = []

pos.append(0) #char index 0


for i in myStr:

    if i == i.upper():

        iCount = iCount+1

        pos.append(myStr.index(i))


pos.append(len(myStr)) #char index = last index


print("there are " + str(iCount+1) + " words")

print(pos)


words = []


for j in pos:

    if pos.index(j)>0:

        words.append(myStr[pos[pos.index(j)-1]:j])



print(words)

Nessun commento:

Posta un commento

Python string split camel case - version 2

Solution with filter() pos=[] pos.append(0) def chkUcase(x):     if x == x.upper():         pos.append(myStr.index(x))         return True  ...