Python list compliance and for statement questions

Asked 2 years ago, Updated 2 years ago, 126 views

0 [([, SS, 0, 1), (golf, NNG, 1, 2), (), SS, 3, 1)...
1 [(Golf, NNG, 0, 2), (Games, XSN, 2, 1), (,, SP, 3, 1...)
2 [(Golinis, NNP, 0, 4), (JX, 4, 1), (Sudden growth, NNG, ...)]
3 [(<, SS, 0, 1), (Summary, NNG, 1, 2), (>, SS, 3, 1)...
4 [(What the hell, MAG, 217, 3), (what, NP, 221, 1), (Lee, VCP,...)

And what I'm trying to extract is

I want to extract the number 0 of each index such as '[', 'Golf', 'Golf', 'Golf', 'Golf', and 'Golinis' at the beginning.

The format is a list.

forms=[]
for t in range(len(df)):

    forms.append(t)

I think I should put something in between, how should I squeeze it?

list-comprehension python

2022-09-20 11:00

1 Answers

I think the questioner can do it on his own.

See if this is the case.

terms = []
for t in df:
    # 't' is '[(Golinis, NNP, 0, 4),'(JX, 4, 1)'(Rapid growth, NNG, ...)'.` 
    for t_i in t:
        # 't_0' is '(Golinis, NNP, 0, 4)'
        # 't_1' is '(JX, 4, 1)'
        # "t_i" is...
        terms.append(t_i[0])


2022-09-20 11:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.