I'm stuck on PS5_ghost, I've got it all except how to test for word fragments that will never become words. I noticed get_frequency_dict() in the given helper code, so I'm guessing that might be what I need. But I don't really see how that's going to help me. I'm thinking a search (binary or newton-Raphson) to see if it exists. Can anyone give me a clue?
the startswith() str method helps -> word.startswith(fragment) you could just run thru the word list i used a binary search
I'm not sure we learned that yet, I think we're still supposed to be doing this all from scratch still. But I think you're reply helped anyway, I'm going to try to make a function based on what you described.
in case it helps, the get_frequency_dict() function is this one: def get_frequency_dict(sequence): """ Returns a dictionary where the keys are elements of the sequence and the values are integer counts, for the number of times that an element is repeated in the sequence. sequence: string or list return: dictionary """ # freqs: dictionary (element_type -> int) freq = {} for x in sequence: freq[x] = freq.get(x,0) + 1 return freq
I didn't need to use get_frequency_dict for ghost. this is not a class in Python. You need not restrict yourself to the portions of Python that they expose to you in the lectures. There is no difference between using the startswith() method and constructing a slice of the word to compare with the fragment
Join our real-time social learning platform and learn together with your friends!