Re: split() and string.whitespace

2008-11-04 Thread bearophileHUGS
MRAB: > I also had the thought that the backtick (`), which is not used in > Python 3, could be used to form character set literals (`aeiou` => > set("aeiou")), although that might only be worth while if character > sets were introduced as an specialised form of set. Python developers have removed

Re: split() and string.whitespace

2008-11-04 Thread MRAB
On Nov 4, 8:00 pm, [EMAIL PROTECTED] wrote: > MRAB: > > > It's interesting, if you think about it, that here we have someone who > > wants to split on a set of characters but 'split' splits on a string, > > and others sometimes want to strip off a string but 'strip' strips on > > a set of character

Re: split() and string.whitespace

2008-11-04 Thread bearophileHUGS
MRAB: > It's interesting, if you think about it, that here we have someone who > wants to split on a set of characters but 'split' splits on a string, > and others sometimes want to strip off a string but 'strip' strips on > a set of characters (passed as a string). That can be seen as a little in

Re: split() and string.whitespace

2008-11-04 Thread Chaim Krause
That is a very creative solution! Thank you Scott. > Or, for faster per-repetition (blending in to your use-case): > >      import string >      SEP = string.maketrans('abc \t', '     ') >      ... >      parts = 'whatever, abalone dudes'.translate(SEP).split() >      print parts > > ['wh', 'tever

Re: split() and string.whitespace

2008-11-03 Thread Scott David Daniels
Steven D'Aprano wrote: On Fri, 31 Oct 2008 12:18:32 -0700, Chaim Krause wrote: I have arrived here while attempting to break down a larger problem. I got to this question when attempting to split a line on any whitespace character so that I could then add several other characters like ';' and ':

Re: split() and string.whitespace

2008-10-31 Thread Steven D'Aprano
On Fri, 31 Oct 2008 12:18:32 -0700, Chaim Krause wrote: > I have arrived here while attempting to break down a larger problem. I > got to this question when attempting to split a line on any whitespace > character so that I could then add several other characters like ';' and > ':'. Ultimately spl

Re: split() and string.whitespace

2008-10-31 Thread MRAB
On Oct 31, 6:57 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Fri, 31 Oct 2008 11:53:30 -0700, Chaim Krause wrote: > > I am unable to figure out why the first two statements work as I expect > > them to and the next two do not. Namely, the first two spit the sentence > > into its com

Re: split() and string.whitespace

2008-10-31 Thread Chaim Krause
On Oct 31, 2:12 pm, Chaim Krause <[EMAIL PROTECTED]> wrote: > The documentation I am referencing states... > > The sep argument may consist of multiple characters (for example, "'1, > 2, 3'.split(', ')" returns "['1', '2', '3']"). > > So why doesn't the latter two split on *any* whitespace characte

Re: split() and string.whitespace

2008-10-31 Thread Chaim Krause
I have arrived here while attempting to break down a larger problem. I got to this question when attempting to split a line on any whitespace character so that I could then add several other characters like ';' and ':'. Ultimately splitting a line on any char in a union of string.whitespace and som

Re: split() and string.whitespace

2008-10-31 Thread Chaim Krause
The documentation I am referencing states... The sep argument may consist of multiple characters (for example, "'1, 2, 3'.split(', ')" returns "['1', '2', '3']"). So why doesn't the latter two split on *any* whitespace character, and is instead looking for the sep string as a whole? -- http://mai

Re: split() and string.whitespace

2008-10-31 Thread Chris Rebert
On Fri, Oct 31, 2008 at 11:53 AM, Chaim Krause <[EMAIL PROTECTED]> wrote: > I am unable to figure out why the first two statements work as I > expect them to and the next two do not. Namely, the first two spit the > sentence into its component words, while the latter two return the > whole sentence

Re: split() and string.whitespace

2008-10-31 Thread Tim Chase
I am unable to figure out why the first two statements work as I expect them to and the next two do not. Namely, the first two spit the sentence into its component words, while the latter two return the whole sentence entact. import string from string import whitespace mytext = "The quick brown f

Re: split() and string.whitespace

2008-10-31 Thread Marc 'BlackJack' Rintsch
On Fri, 31 Oct 2008 11:53:30 -0700, Chaim Krause wrote: > I am unable to figure out why the first two statements work as I expect > them to and the next two do not. Namely, the first two spit the sentence > into its component words, while the latter two return the whole sentence > entact. > > imp