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":
|'alpha's = 'alpha.beta.gamma'
s[ 0: s.find( '.', 0 )]
|'beta's[ 6: s.find( '.', 6 )]
|'gamm's[ 11: s.find( '.', 11 )]
. 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?
|'alpha's = 'alpha.beta.gamma'
s[ 0: s.find( '.', 0 )]
|'beta's[ 6: s.find( '.', 6 )]
|'gamm's[ 11: s.find( '.', 11 )]
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'
|'alpha's[ 0: s.find( '.', 0 )]
|'beta's[ 6: s.find( '.', 6 )]
|'gamm's[ 11: s.find( '.', 11 )]
. 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?
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":
|'alpha's = 'alpha.beta.gamma'
s[ 0: s.find( '.', 0 )]
|'beta's[ 6: s.find( '.', 6 )]
|'gamm's[ 11: s.find( '.', 11 )]
. 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..
... s[ start_index:s.index( '.', start_index ) ]start_index = 11 #to cure the issue-raised
try:
['alpha', 'beta', 'gamma']s.split( "." )
On 06/03/2023 11.59, aapost wrote:
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":
|'alpha's = 'alpha.beta.gamma'
s[ 0: s.find( '.', 0 )]
|'beta's[ 6: s.find( '.', 6 )]
|'gamm's[ 11: s.find( '.', 11 )]
. 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..
To expand on the above, answering the OP's second question: the numeric
value is len( s ).
If the repetitive process is required, try a loop like:
>>> start_index = 11 #to cure the issue-raised
>>> try:
... s[ start_index:s.index( '.', start_index ) ]
... except ValueError:
... s[ start_index:len( s ) ]
...
'gamma'
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.
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":
|'alpha's = 'alpha.beta.gamma'
s[ 0: s.find( '.', 0 )]
|'beta's[ 6: s.find( '.', 6 )]
|'gamm's[ 11: s.find( '.', 11 )]
. 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?
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.
['alpha', 'beta', 'gamma']s='alphaAbetaBgamma'
import re
re.split(r'A|B|C', s)
On 6/03/23 11:43 am, Stefan Ram wrote:
A user tries to chop of sections from a string,What's wrong with re.split() in that case?
but does not use "split" because the separator might become
more complicated so that a regular expression will be required
to find it.
|'abc''abc'[ 0: len( 'abc' )]
|'abc''abc'[ 0: int(9E99) ]
Am 05.03.23 um 23:43 schrieb Stefan Ram:['alpha', 'beta', 'gamma']
The following behaviour of Python strikes me as being a bitOK, so if you want to use an RE for splitting, can you not use
"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.
re.split() ? It basically works like the built-in splitting in AWK
['alpha', 'beta', 'gamma']s='alphaAbetaBgamma'
import re
re.split(r'A|B|C', s)
Christian
s = 'alpha.beta.gamma'; trenne(s)
['alpha', 'beta', 'gamma']s = 'alpha---beta gamma'; trenne(s)
['alpha', 'beta', 'gamma']s = 'alpha---beta gamma999'; trenne(s)
['tau', 'beta', 'omega']s = '1 tau===beta+omega '; trenne(s)
['alpha', 'beta', 'gamma']s = 'AalphaBbetaGgamma'; trenne(s)
['a', 'bc', 'xy', 'z']s = 'a.😁bc\u1234xy z'; trenne(s)
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 145:30:54 |
| Calls: | 12,089 |
| Calls today: | 2 |
| Files: | 15,000 |
| Messages: | 6,517,497 |