Posted by Kevin D Smith @ 3:26 am on March 22nd 2007
I’ve been working through Dave Thomas’ CodeKata for the past few weeks. I get to about one or two a week. I just finished number six which has been the most fun so far. Dave’s told about his solution in Ruby that was 25 lines and took 1.5s on his 1GHz machine. Since I’m more of a Python fan than a Ruby fan, I thought I’d take a shot at his numbers. Here is my 7 line solution.
words = {}
for word in open('wordlist.txt'):
key = ''.join(sorted(list(word.strip().lower())))
words.setdefault(key, []).append(word.strip())
for v in sorted(words.values()):
if len(v) > 1:
print ' '.join(v)
This could be shortened to 5 lines, but isn’t quite as readable.
words = {}
for word in open('wordlist.txt'):
words.setdefault(''.join(sorted(list(word.strip().lower()))), []).append(word.strip())
for v in [x for x in sorted(words.values()) if len(x) > 1]:
print ' '.join(v)
On my 1.83GHz MacBook, this took 0.56s.
Posted by Kevin D Smith @ 3:41 am on March 2nd 2007
Well, it’s been over two months without TV. I was holding out pretty well, but my wife couldn’t take it any more and we broke down and got a new TV. I think we would have made it, but this Colorado winter has been rather harsh. Since we don’t know anyone in the neighborhood yet, entertainment was getting pretty scarce. I guess the good news is that we’re not wasting as much money on it each month since we’re getting a package deal from Comcast that includes internet, phone, and cable.
Posted by Kevin D Smith @ 3:36 am on March 2nd 2007
While I didn’t get to go to PyCon this year, I read Guido van Rossum’s impressions. It’s quite apparent that the use of Python in One Laptop Per Child project is going to be driving the development of Python in the following months. One paragraph on Guido’s blog that really excites me is shown below.
The software is far from finished. An early version of the GUI and window manager are available, and a few small demo applications: chat, video, two games, and a web browser, and that’s about it! The plan is to write all applications in Python (except for the web browser), and a “view source” button should show the Python source for the currently running application. In the tradition of Smalltalk (Alan Kay is on the OLPC board, and has endorsed the project’s use of Python) the user should be able to edit any part of a “live” aplication and see the effects of the change immediately in the application’s behavior. (A versioned document store will make it possible to roll back disastrous changes.) This is where Krstic wants my help: he hopes I can work magic and implement this feature for Python. I got started right away during the conference, with a reimplementation of python’s reload() function that can patch classes and functions in place. Even this small component still has a long way to go; a checkpoint of the work in progress is checked into subversion as part of the Py3k standard library. That’s not where the rest of my OLPC work will show up; they use GIT for source control, so I will get to learn that.
While I think the changes to Python in the past couple of years have been a bit esoteric (and a bit disheartening), having the ability to update live code would make me as happy as a peach orchard hog! It might even be the tipping point to get Blaine, my friendly neighborhood Smalltalk apologist, to start using Python.