problem with for and if
Shiyao Ma
i at introo.me
Mon Jan 5 09:38:02 EST 2015
On Jan 05 at 06:27 -0800, 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
def gen():
count = 0
for a in zmienna:
# we assume szukana is a single letter
if szukana == a:
count+=1
else:
continue
return count
More preferably, you should repetitively use "str.find"
Or just use `max(0,len(zmienna.split(szukana))-1)`
--
Shiyao Ma
http://introo.me
More information about the Python-list
mailing list