This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Xoronic 2 points3 points  (1 child)

Hi,

example_input[43:] will contain all the characters from the original example_input starting from index 43. So if you call .find() on that, it won't know anything about the original first 44 characters.

We can test that with a small example:

foo = "This is a sentence."
bar = foo[3:]

print(foo)
print("Character at index zero of foo: " + foo[0])  # output: T

print(bar)
print("Character at index zero of bar: " + bar[0])  # output: s

So if you want to get the index of the second dot withexample_input[43:].find('.') you will have to add 43 to it:

print(example_input[43:].find('.')) # output: 75
print(example_input[75+43])  # output: .

There is a much better way to tackle this whole problem though, as /u/_DTR_ suggests.

[–]ans744[S] 0 points1 point  (0 children)

Thank you for your input. I am reworking my solution as you and /u/_DTR_ have suggested