Re: Any algorithm to preserve whitespaces?
Santosh Kumar wrote:
> But I can; see: http://pastebin.com/ZGGeZ71r
You have messed with your cat command -- it adds line numbers.
Therefore the output of
cat somefile | ./argpa.py
../argpa.py < somefile
to confirm my analysis. As to why your capitalisation algorithm fails on
those augmented lines: the number is separated from the rest of the line by
a TAB -- therefore the first word is "1\tthis" and the only candidate to be
capitalised is the "1". To fix this you could use regular expressions (which
I wanted to avoid initially):
>>> parts = re.compile("(\s+)").split(" 1\tthis is it")
['', ' ', '1', '\t', 'this', ' ', 'is', ' ', 'it']
Process every other part as you wish and then join all parts:
>>> parts[::2] = [s.upper() for s in parts[::2]]
['', ' ', '1', '\t', 'THIS', ' ', 'IS', ' ', 'IT']
>>> print "".join(parts)
1 THIS IS IT
|All times are GMT. The time now is 01:46 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.