problem with for and if

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jan 6 02:12:20 CET 2015


Dariusz Mysior wrote:

> I want search count of szukana in zmienna but code below counting all 12
> letters from "traktorzysta" word
> 
> szukana="t"
> zmienna="traktorzysta"
> 
> 
> def gen():
>     count=int(0)
>     for a in zmienna:
>         if szukana in zmienna:
>             count+=1
>         else:
>             continue
>     return count


I think what you want is:

zmienna.count(szukana)




-- 
Steven




More information about the Python-list mailing list