In: Computer Science
Write a function that takes a valid stringlist and returns the index of the smallest element in the list represented by the stringlist. You may not use split().
Examples:
>>> stringlist min index('[123,53,1,8]') # 1 is smallest2
>>> stringlist min index('[1,2,345,0]') # 0 is smallest3
>>> stringlist min index('[5] ') # 5 is smallest0
def stringlist_min_index(s):
l=1
i=0
li=[]
while(l<len(s)-2):
j=s.find(',',l,len(s)-1)
li.append(int(s[l:j].strip()))
l=j+1
li.append(int(s[l:-1].strip()))
result = 0
i = 1
while i < len(li):
if li[result] > li[i]:
result = i
i += 1
return result
# Testing
print(stringlist_min_index('[123 ,53 ,1 ,8]'))
print(stringlist_min_index('[1 ,2 ,345 ,0]'))
print(stringlist_min_index('[5]'))
PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT
SECTION