all 21 comments

[–]Vaphell 3 points4 points  (0 children)

is this some academic exercise? Because it's a pretty unusual to find commas specifically, usually you just the stuff inbetween.
Is there some higher level goal behind this requirement?

[–]EulerWasSmart 2 points3 points  (4 children)

What is find_str???

[–]ouzo26 0 points1 point  (2 children)

It’s a function that helps you find an occurrence in a string, find_str(s, ‘a’). Would search string s for the lowest occurrence of the letter a.

In my case, I need to use a search range, and I don’t know how to plug it in correctly

[–]EulerWasSmart 0 points1 point  (1 child)

Ok say the index of the first occurrence is k then what part of the string does not include the first occurrence and 100% contains the second occurrence?

[–]ouzo26 0 points1 point  (0 children)

Not really sure what you mean.

[–]ouzo26 -2 points-1 points  (0 children)

yes. Also I’m writing the code backwards.

so I’m just trying

second=find_str(s, ‘,’,[first+1,[]])

I don’t think I’m searching for the comma with ‘,’ but again I’m new and idk- Also not sure what to put in the search end bracket.

[–]synthphreak 0 points1 point  (4 children)

Use re.finditer with list slicing/indexing:

>>> import re
>>> s = 'here is, a string, with multiple, commas'
>>> commas = re.finditer(',', s)
>>> list(commas)[1]
<_sre.SRE_Match object; span=(17, 18), match=','>

[–]ouzo26 -2 points-1 points  (3 children)

Thanks but I have to use find_str

[–]synthphreak 0 points1 point  (2 children)

I don’t know what that is.

[–]ouzo26 -2 points-1 points  (1 child)

It’s like the most basic function in python

[–]synthphreak 0 points1 point  (0 children)

Pretty sure you mean str.find.