0

This is an assignment so I'd like to get informative hints rather than code to copy.

We are supposed to make a program that automaticaly completes words. (Gives out suggestions based on letters written.)

The suggestions for these words are taken from a list called "alphabetical.csv", which is a separate data file, containing around 90000 different words.

I've been thinking of making lists to be printed out to the user, suggesting all words beginning with a certain letter, and possibly the next, and the next, and so on, but I've no idea of how to implement that effectively.

There is a skeleton which must be used with the assigment which looks like this:

def main():
    """Initialize main loop."""
    word = ""

    while word != "q":
        word = input("Type word: ").lower()
        print("Autocompletion finished: ", autocomplete())

def autocomplete():
    """Return autocomplete suggestions."""
    pass

main()

We are not supposed to import anything, and the program itself is supposed to run in a terminal.

jwpfox
  • 5,124
  • 11
  • 45
  • 42
  • 1 - Open the csv data file. 2 - Read the contents of the data file into a data structure (list, dict, whatever). 3 - Read up on `startswith` http://stackoverflow.com/questions/8802860/checking-whether-a-string-starts-with-xxxx. When you have some of that written and working you can seek more help but asking for help without even doing the bare basics suggests that you may want to consider if you have signed up for the right course. Perhaps complex problem solving like programming is not for you. – jwpfox Oct 21 '16 at 23:41

1 Answers1

0

You will first need to open a file and to read it. Then you will have to search words which start with a substring, str.startswith could help you. Since you apparently already know loops and the print function, you should be able to do something functionnal.

Tryph
  • 5,946
  • 28
  • 49