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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -