How do I read the following lines of code?

45 Views Asked by At

Apologies for the basic question as I am quite new to the topic.

 conlltags = [(word, pos, chunktag) for ((word,pos),chunktag)
                     in zip(sentence, chunktags))]

Can you please break the code above in the format given below:

for i in exampleSentence:
    letterByLetter = i
    print(letterByLetter)
2

There are 2 best solutions below

0
On BEST ANSWER

I think it is better for you to look up the following subjects:

  • List comprehensions - link
  • zip() function - link

This will give you a better understanding of what is happening and it is very useful to use in one of your future projects!

0
On

The simpliest form I know:

conlltags = []
for i in range(min(len(sentence), len(chunktags))):
    conlltags.append((sentence[i][0], sentence[i][1], chunktags[i]))