Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Any algorithm to preserve whitespaces? (http://www.velocityreviews.com/forums/t956704-re-any-algorithm-to-preserve-whitespaces.html)

Mitya Sirenef 01-19-2013 07:04 PM

Re: Any algorithm to preserve whitespaces?
 
On 01/19/2013 05:13 AM, Santosh Kumar wrote:
> I have a working script which takes argv[1] as an input, deassembles
> each line, and then each word. Then after it capitalizes all its word
> (upcases the first letter) and then prints it out on the stdout.
>
> That script does the capitalization work fine, but, when it reassemble
> the the words, it does it like this:
>
> lines.append(' '.join(words))
>
> The biggest problem is, even when the input file has many spaces, it
> strips it down to one.
>
> A file with this line:
>
> This line contains many spaces
> becomes:
>
> This Line Contains Many Spaces
>
>
> The whole script will look clumsy here. I have put it up on GitHub,
> here is it: https://github.com/santosh/capitaliz...ter/capitalizr


You know that mystr.title() can do this?

- m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/



All times are GMT. The time now is 09:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57