tynation.com

Sunday, February 26, 2012

How disappointing

For a while I've been thinking of a way to write a program in python that would find all the spaces in a string of words and replace them with underscores. I was thinking of ways that I could write definitions and if statements on how to search the words for the spaces then replace the word, but no, after a bit of reading I find out that I can do this with 2 lines of code.

word = raw_input('Write a phrase and I will change spaces with underscores: ')
print word.replace(' ', '-')

Now I need something more challenging to do! I guess I'll read more and see if I can't come up with some better ideas.

No comments: