I am trying to compare and see if a particular character exists in the string, but when i try to access the character which is in another string, its throws an error 'argument of type 'int' is not iterable'. How do i access the character from a string without causing the error?
def lengthOfLongestSubstring(self, s: str) -> int:
longStrLen = 0
totalStrLen = len(s)
holderString = ""
holderString += s[0]
longStrLen = 0
for i in range(1,totalStrLen-1):
if s[i] not in holderString:
holderString += s[i]
else:
if longStrLen < len(holderString):
longStrLen = len(holderString)
holderString = 0
return longStrLen
TypeError: argument of type 'int' is not iterable at Line
if s[i] not in holderString:
holderString = 0You've reassigned holderString to an integer, and it's not a string any more.catwill run butcaaatwill notselfanywhere in the body.selfit's from a class, but for the minimal reproducible example, the asker (correctly) only provided the nonworking snippet of code