<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 08/28/2013 08:57 PM, MRAB wrote:<br>
</div>
<blockquote cite="mid:521E47FE.6040809@mrabarnett.plus.com"
type="cite">On 28/08/2013 19:42, Marco Buttu wrote:
<br>
<blockquote type="cite" style="font-weight: bold; font-style:
italic; color: #000099;">What do you think about an optional
`keepsep` argument in str.split(),
<br>
in order to keep the separator?
<br>
Something like the `keepends` of str.splitlines():
<br>
<br>
>>> 'I
am\ngoing\nto...'.splitlines(keepends=True)
<br>
['I am\n', 'going\n', 'to...']
<br>
<br>
For instance:
<br>
<br>
>>> 'python3'.split('n')
<br>
['pytho', '3']
<br>
>>> 'python3'.split('n', keepsep=True)
<br>
['python', '3']
<br>
<br>
</blockquote>
If it's a <span class="moz-txt-underscore"><span
class="moz-txt-tag">_</span>separator<span class="moz-txt-tag">_</span></span>,
should it be attached to the previous part?
<br>
Shouldn't it be:
<br>
<br>
>>> 'python3'.split('n', keepsep=True)
<br>
['pytho', 'n', '3']
<br>
</blockquote>
<br>
It should be attached to the previous part, exactly as my example<br>
<br>
<blockquote cite="mid:521E47FE.6040809@mrabarnett.plus.com"
type="cite">
<br>
What's your use-case?
</blockquote>
<br>
I think it could be useful in a lot of use-cases, when you have to
parse a string. For instance,<br>
if you have some source code, and you want to write it better<em
style="font-weight: bold; font-style: normal; color: rgb(68, 68,
68); font-family: arial, sans-serif; font-size: small;
font-variant: normal; letter-spacing: normal; line-height:
12.800000190734863px; orphans: 2; text-align: left; text-indent:
0px; text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-size-adjust: auto;
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
255); "></em>:<br>
<br>
>>> source_code = "int a = 33;cout << a <<
endl;return 0;"<br>
>>> print('\n'.join(source_code.split(';')))<br>
int a = 33<br>
cout << a << endl<br>
return 0<br>
<br>
>>> print('\n'.join(source_code.split(';', keepsep=True)))<br>
int a = 33;<br>
cout << a << endl;<br>
return 0;<br>
<pre class="moz-signature" cols="72">--
Marco Buttu
INAF Osservatorio Astronomico di Cagliari
Loc. Poggio dei Pini, Strada 54 - 09012 Capoterra (CA) - Italy
Phone: +39 070 71180255
Email: <a class="moz-txt-link-abbreviated" href="mailto:mbuttu@oa-cagliari.inaf.it">mbuttu@oa-cagliari.inaf.it</a></pre>
</body>
</html>