I am trying to write a function which can remove leading spaces and replace spaces in between the string with ',' and then split the string by ',' to individual elements.
split_entry = ['ENTRY', ' 102725023 CDS T01001']
res = []
def ws(list):
for x in split_entry:
entry_info = x.lstrip() #remove leading spaces at the start of string (' 102725023)
entry_info = re.sub('\s+',', ',entry_info) #replaces multiple spaces with ',' within a string
if(re.search("^\d+",entry_info)): #if element starts with digits '102725023'
l = entry_info.split(", ", entry_info) #split by ','
print (l[0]) #get first element
#return l[0]
ws(split_entry)
I would like to get the first element of the second list element (102725023 ). However I am getting following error while running above code.
TypeError: 'str' object cannot be interpreted as an integer
Any suggestions to resolve it. Thanks