New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let "".split()
split according to _any_ whitespace
#86
Comments
On the fence on this. JavaScript uses What are the characters that are considered "empty strings"? I see |
Caveat: I'm not a big fan of JavaScript, so I'm biased on this issue. From a practical standpoint, if I wanted to do something with every character in a string in Python, I would use for c in "xyz":
do_something(c) or chars = list("xyz") Also from a practical standpoint: If ABS were to use JavaScript's understanding of the default, in order to split a simple string like Also, if we look how Bash does it, it would split an unquoted environment variable at the characters in s=$(printf 'X Y\tZ')
for c in $s; do echo $c; done
X
Y
Z PS: If ABS decides to go with Python or Bash's strategy, ABS should possibly consider letting >>> '\t \nX\f\v'.strip()
'X' |
PPS: I just tried JavaScript: $ js52
js> "XYZ".split()
["XYZ"]
js> "XYZ".split("")
["X", "Y", "Z"]
js> ^D
$ node
> "XYZ".split()
[ 'XYZ' ]
> "XYZ".split("")
[ 'X', 'Y', 'Z' ]
> |
You won me with the for in example :) I think it makes sense to do for char
in str.split()
…On Thu, Dec 27, 2018 at 3:18 PM Klaus Alexander Seistrup < ***@***.***> wrote:
Caveat: I'm not a big fan of JavaScript, so I'm biased on this issue.
From a practical standpoint, if I wanted to do something with every
character in a string in Python, I would use
for c in "xyz":
do_something(c)
or
chars = list("xyz")
Also from a practical standpoint: If ABS were to use JavaScript's
understanding of the default, in order to split a simple string like "X
Y\tZ" I would have to loop over the string and its substrings with
multiple calls to .split() and .trim(), which seems a bit over the top.
Also, if we look how Bash does it, it would split an unquoted environment
variable at the characters in $IFS, that defaults to " \t\n":
s=$(printf 'X Y\tZ')for c in $s; do echo $c; done
X
Y
Z
------------------------------
PS: If ABS decides to go with Python or Bash's strategy, ABS should
possibly consider letting .trim() without any arguments follow the same
logic. E.g., in Python:
>>> '\t \nX\f\v'.strip()'X'
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#86 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAUC5Cx0h_XXhRCJeLs5WRut6YPMT_35ks5u9Kx8gaJpZM4ZijnX>
.
|
Python's
"".split()
method has a useful feature: When invoked without any arguments, the string is split according to any whitespace, and empty strings are discarded from the result:Having a similar logic in ABS would make it much easier to split strings without having to resort to calling
.trim()
on the resulting elements.The text was updated successfully, but these errors were encountered: