count..Please help me in the below query


def count(sequence,item):
 print "newList", newSeq ,"size ",size 
 for i in range(0,size-1):
  if (item==newSeq[i]):
      print "I am in if loop: ",newSeq[i]
 print "result",result
 return result

My function should return result value,But its just returning 0.
No idea whats happening


Do you call your function?


Yes.While printing,Its printing the correct result..But not working when its returning


I don't understand what you mean, if it is about the print and return statements in your function you must take into account that print and return statements work differently :slight_smile:


Can you please tell me where I am wrong


i had the same issue. I changed the for loop from len(sequence) rather than len(sequence)-1

you need to change your for loop.

for i in range(0,size):

Also, we shouldnt use list function in this execution. You can directly say len(sequence)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.