[Python-ideas] Adding "Typed" collections/iterators to Python
ncoghlan at gmail.com
Tue Dec 20 00:26:49 CET 2011
On Tue, Dec 20, 2011 at 9:10 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 12/18/2011 9:24 PM, Nathan Rice wrote:
>>> Another bad example, since that's just a really verbose way of writing
>> The python interpreter says otherwise...
>>>>> foo = "line 1\nline 2\nline 3"
>> 'Line 1\nline 2\nline 3'
>>>>> "\n".join(s.capitalize() for s in foo.split("\n"))
>> 'Line 1\nLine 2\nLine 3'
> Using the right method (as Nick corrected himself):
> 'Line 1\nLine 2\nLine 3'
Nope, foo.title() isn't exactly the same - Nathan's variant
capitalises the first letter of each line, foo.title() would
capitalise the first letter of each word.
Not a common operation, but split + capitalise + join is likely the
simplest way to spell it.
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas