Reading a post from a Planet PythonBrasil blog today, our friend Rodrigo Cacilhas has proposed some approaches on the Oddwords puzzle where the objective is to invert the odd words in a phrase.
The post can be seen here: http://kodumaro.blogspot.com/2007/05/oddwording.html
I created a small solution based on list comprehension and the and-or trick. It´s like this:
text= "abc def ghi"
print " ".join([(x%2 == 0 and y or y[::-1]) for x,y in enumerate(text.split())])
It shows how powerful list comprehensions can be.
Friday, May 11, 2007
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment