lunedì 1 febbraio 2021

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

    else:

        return False



myStr = "myStringInPython"


#get only letters in uppercase

ucase = filter(chkUcase, myStr)

ucase=list(ucase)

print(ucase)



print("there are " + str(len(list(ucase))+1) + " words")


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


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  ...