I'm trying to write a method that takes a substring consisting of two parts:
name: idnumber
Yes the name and the id are separated by a colon (:), for example:
A:1313
B:4141
The method should return A for the first example and B for the second but it also should accept special cases, for example:
A$%#@$@#!__231:2
A:::$@$@:::!$@:4
The above code should return A$%#@$@#!__231 for the first line and A:::$@$@:::!$@ for the second line.
I tried to do this recursively and here is my code:
j=0
def name(input):
global j
item = ''
item = input[j:]
if ':' in item:
return name(input[j+1:])
else:
return input[:j - 1]
This code returns nothing and I'm not sure why it's not working.
Any help is appreciated.
split()A$@$@:::::$@$!:4, here I have multiple ":", splitting by ":" results in a faulty output.