> Den 05/01/2015 kl. 22.45 skrev Dariusz Mysior <mysior.da...@gmail.com>: > > I try develop this code to get a number of position this letter in word, and > I have it but for example if i search letter "t" I get "1, 5, b", why I get b > instead of 11??? > > def gen2(): > count=0 > count2=0 > for a in zmienna: > count2+=1 > if a==szukana: > count+=1 > pozycja.append(count2) > > return pozycja > print("3. Literka '",szukana,"' w słowie ",zmienna, > "wystąpiła " ,gen(),"razy w kolejności") > #print(gen2()) > > print(", ".join(["%x" % a for a in gen2()]))
Whoa, that code is really convoluted. It won't even compile, as far as I can see. Try this instead: import re def indices(needle, haystack): return [match.start() for match in re.finditer(re.escape(needle), haystack)] If your search strings can be overlapping, you'll need another solution. Erik -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4551A371-1AAA-405C-BC30-2C7B3044D88B%40cederstrand.dk. For more options, visit https://groups.google.com/d/optout.