I am not commenting on the technique or why it is chosen just the part where the last search looks for a non-existent period:
s = 'alpha.beta.gamma' ... s[ 11: s.find( '.', 11 )] What should "find" do if it hits the end of a string without finding the period you claim is a divider? Could that be why gamma got truncated? Unless you can arrange for a terminal period, maybe you can reconsider the approach. -----Original Message----- From: Python-list <python-list-bounces+avi.e.gross=gmail....@python.org> On Behalf Of aapost Sent: Sunday, March 5, 2023 6:00 PM To: python-list@python.org Subject: Re: Cutting slices On 3/5/23 17:43, Stefan Ram wrote: > The following behaviour of Python strikes me as being a bit > "irregular". A user tries to chop of sections from a string, > but does not use "split" because the separator might become > more complicated so that a regular expression will be required > to find it. But for now, let's use a simple "find": > > |>>> s = 'alpha.beta.gamma' > |>>> s[ 0: s.find( '.', 0 )] > |'alpha' > |>>> s[ 6: s.find( '.', 6 )] > |'beta' > |>>> s[ 11: s.find( '.', 11 )] > |'gamm' > |>>> > > . The user always inserted the position of the previous find plus > one to start the next "find", so he uses "0", "6", and "11". > But the "a" is missing from the final "gamma"! > > And it seems that there is no numerical value at all that > one can use for "n" in "string[ 0: n ]" to get the whole > string, isn't it? > > I would agree with 1st part of the comment. Just noting that string[11:], string[11:None], as well as string[11:16] work ... as well as string[11:324242]... lol.. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list