Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 22 Online
OpenStudy (anonymous):

I updated my 'Ghost' game http://ideone.com/2eCs0 would love to hear feedback particularly on the binary search used and if anyone came up with a better way to use binary search, and whether binary search is worthwhile, is 'if string_word in word_list', a linear search? And any other tips/problems/improvements.

OpenStudy (anonymous):

join is a method of all strings - you could get away with ''.join(word) if you wanted to and not have to import string at lines 132 and 173 why are you using string.join(word,'') instead of just using word? i found the startswith() string method helpful also, you can compare strings with the < and > operators i found that these two really simplified my binary search http://ideone.com/92vuJ http://docs.python.org/library/stdtypes.html#str.startswith i didn't actually run your code to see if it worked. I think a binary search is tailor made for ghost I did use the in operator to see if the fragment was actually a (whole) word in the list before i started the search - that was probably a duplication of effort, the search could do that as well. I think that the in/not in operators are implemented as an optimized fast (written in C) search so ............. i' have decided to write things so that they are easy to read and then only worry about optimizing it after i find that they take too long. "Strings are compared lexicographically using the numeric equivalents (the result of the built-in function ord()) of their characters. Unicode and 8-bit strings are fully interoperable in this behavior" from: http://docs.python.org/reference/expressions.html#notin mine: http://ideone.com/S5QrD

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!