Using for/if to keep count in python -
i'm attempting create function finds how many times item occurs in function. have code below, ends counting items in list(6), not 1 want( in case 1). know i'm not returning anything, print me see answer get.
def count(sequence, item):     found = 0     in sequence:         if item in sequence:             found = found + 1     print found  count([1,2,1,2,4,5], 1) 
try this
 def count(sequence, item):         found = 0         in sequence:             if == item:                 found = found + 1         print found      count([1,2,1,2,4,5], 1) 
Comments
Post a Comment