Re: [Python-ideas] oneof() and multi split and replace for stirngs

On 1/23/07, Josiah Carlson <jcarlson@uci.edu> wrote:
I had talked to others and the concensus was against the tuples for ugliness. s.split((a,b), c) wasn't a popular choice, but s.split(oneof(a, b), c) reads better.
It seems like we have a history of useful string operations being moved away from "use re" to "dont use re", such that the slightly recent startswith and endswith methods, and even split and replace themselves. I would like to see less reasons for people to worry with regular expressions until they actually need them. If we can provide a better way to get the job done, that seems like a great idea. ALSO The oneof type isn't just a single use thing. Usecode may often make use of it, and other types could benefit such as doing a lookup with d[oneof(1,2,3)] (where order would matter for priority). I think this semantic collection type would be very useful in a number of contexts where we would currently just loop or duplicate code. -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/

"Calvin Spealman" <ironfroggy@gmail.com> wrote:
oneof = tuple Now it reads better. Stick with tuple.
Well, startswith and endswith is still computable without re or the methods, and turns out to be faster (for certain startswith and endswith operations) to do... if st[:X] == sub: or if st[-X:] == sub: (more specifically, when sub is a constant and X is previously-known)
I took the time to look for a thread discussing something like this feature before. And I found it. Turns out I was wrong: http://mail.python.org/pipermail/python-dev/2005-September/056119.html That thread discusses an enhancement to str.[r|l|]strip(), where one could specify a list of strings to be trimmed from the end(s), not only just a group of characters (does the equivalent of .startswith and .endswith). What was the outcome? Use the X-line function that can be defined as Y. I'll stick with "use re". - Josiah

"Calvin Spealman" <ironfroggy@gmail.com> wrote:
oneof = tuple Now it reads better. Stick with tuple.
Well, startswith and endswith is still computable without re or the methods, and turns out to be faster (for certain startswith and endswith operations) to do... if st[:X] == sub: or if st[-X:] == sub: (more specifically, when sub is a constant and X is previously-known)
I took the time to look for a thread discussing something like this feature before. And I found it. Turns out I was wrong: http://mail.python.org/pipermail/python-dev/2005-September/056119.html That thread discusses an enhancement to str.[r|l|]strip(), where one could specify a list of strings to be trimmed from the end(s), not only just a group of characters (does the equivalent of .startswith and .endswith). What was the outcome? Use the X-line function that can be defined as Y. I'll stick with "use re". - Josiah
participants (2)
-
Calvin Spealman
-
Josiah Carlson