-
-
Save zmagg/6235901 to your computer and use it in GitHub Desktop.
f = open("sowpods.txt", "r") | |
canonized_words = {} | |
word1 = "" | |
word2 = "" | |
max_len = 0 | |
for line in f: | |
if len(line) > max_len: | |
sorted_word = ''.join(sorted(line)) | |
if sorted_word in canonized_words: | |
found_word = canonized_words[sorted_word] | |
word1 = line | |
word2 = found_word | |
max_len = len(word1) | |
else: | |
canonized_words[sorted_word] = line | |
print word1 + ", " + word2 |
It's running much faster that that on mine, so I probably have a smaller dictionary. What URL did you pull the sowpods.txt from?
: D you might just have a better CPU...or SSD read rate? http://norvig.com/ngrams/sowpods.txt
hah, also, we all compared 'real' time within hacker school (as opposed to system time). i actually don't understand the differences between the 3 (real, user, sys). i assume you do?
Cool! Now I wanna look at the problem :-}
Real is the clock time spent solving the problem (actual time passed between start and finish)
User is the processor time spent in user mode (not in the kernel) -- if your process runs on more than one CPU at once this can actually be greater than real time.
Sys is the CPU time spent in the application not in user mode -- also can be greater than real if running on more than one CPU -- examples of this are time spent in syscalls, or when in the kernel doing work on behalf of the process.
This solution runs in .130 seconds in my intel core 2 duo 2.4 Ghz, 4GB ram, SSD