Could someone help me with this Python code?
Go to solution
Solved by Sauron,
22 minutes ago, LebowskiBuschemi said:I was referring to the first loop. The one with the enumeration command.
you need that one because you're iterating over a list of sentences, each of which is turned into a list of words with split.
23 minutes ago, LebowskiBuschemi said:Also, regarding the enumerate command, how come we use it in Python? Aren't lists indexed to begin with?
Lists are indexed but they don't contain the index as data. When you use the for command like that you're getting a single element without the index. If you want you can use a less abstract syntax to skip the enumerate:
for i in range(len(doc_list) - 1): words = [token.rstrip(".,").lower() for token in doc_list[i].split()]
but there is no way to determine the index of a list element from the element itself.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now