W
Will McGugan
Hi,
I'd like to suggest an addition to the slice syntax. How about allowing
strings as arguments to slices on strings, and interpret them as the
index of the substring found within the string being sliced. I'm sure I
didnt explain that too well, so here is an example..
#Strings with a negative step would search for the substring from the
end of the string
I have actually implemented something similar in a C++ string class, so
its not completely crazy - but I would be interested in what more
experienced Python developers think of it.
Thanks,
Will McGugan
I'd like to suggest an addition to the slice syntax. How about allowing
strings as arguments to slices on strings, and interpret them as the
index of the substring found within the string being sliced. I'm sure I
didnt explain that too well, so here is an example..
'(parenthesis)'>>> a= "Find the string within the (parenthesis)." #equivalent of a[ a.find('(') : a.find(')', a.find('(') + 1 ) + 1 ]
>>> a['(':')']
#Strings with a negative step would search for the substring from the
end of the string
'.txt'>>> a= 'some/folder/file.txt';
>>> a['.',-1,-1]
I have actually implemented something similar in a C++ string class, so
its not completely crazy - but I would be interested in what more
experienced Python developers think of it.
Thanks,
Will McGugan