if type(prevtag_pair) == list:
word_tag=[]
for row in prevtag_pair:
c =0
x =[]
for col in row:
y=[]
for pair in col:
if len(pair[1])> 0:
y.append(pair[0]+ '_'+pair[1])
else:
y.append(pair[0]+ '_' )
x.append(y)
word_tag.append(x)
I want to convert it in a one liner. But I am getting error. any help would be appreciated.
if type(prevtag_pair) == list:
word_tag = [[y.append(pair[0]+ '_'+pair[1]) if len(pair[1])> 0 else y.append(pair[0]+ '_' ) ] for row in prevtag_pair for col in row for pair in col]
Please correct it iff possible. Thank you.
I/P DATA:
[[[['challenge', 'D'], ['opportunity', 'D'], ['overcoming', 'P'], ['challenge', 'D'], ['opportunity', 'D'], ['higher', 'D'], ['levelthan', 'A']], [['country', 'D'], ['face', 'P'],
['levels', 'N'], ['challenges', 'A'], ['democracy', 'A'],
['foundational', 'P'], ['progress', 'A']], [['challenges', 'A'], ['democracy', 'P'], ['faces', 'N'], ['world', 'D'], ['level', 'A']], [['challenge', 'D'], ['opportunity', 'D'], ['progress', 'A'], ['statement', 'D'], ['reveals', 'N'], ['idea', 'D'],
['challenge', 'D'], ['difficulty', 'D'], ['hardship', 'A'],
['opportunity', 'D'], ['progress', 'A'], ['challenge', 'D'],
['overcome', 'A'], ['challenge', 'D'], ['succeed', 'P'],
['overcoming', 'A'], ['rise', 'A'], ['higher', 'D'],
['level', 'A'], ['progess', 'A']], [['challenges', ['o']],
['enlight', 'N'], ['deal', 'P'], ['ways', 'D'], ['like', 'A'], ['obstacles', 'A'], ['enlights', 'P'], ['afford', 'P'], ['best', 'P'], ['result', 'D'], ['challenges', 'P'], ['like', 'A'], ['opportunity', 'D'], ['progress', 'P'], ['want', 'P'], ['deal', 'P'], ['smartly', 'P'], ['victorious', 'V'],
['looser', 'C'], ['life', 'P']], [['challenge', 'D'],
['problem', 'D'], ['opportunity', 'D'], ['progress', 'A'],
['meansa', 'N'], ['challenge', 'P'], ['problem', 'D'],
['help', 'D'], ['development', 'D'], ['ex', 'P'], ['farmer', 'D'], ['challenging', 'A'], ['grow', 'P'], ['plants', 'A'],
['set', 'P'], ['target', 'P'], ['help', 'V'], ['development', 'A']]]]
O/P: error is coming as [none],[none],.....
Aucun commentaire:
Enregistrer un commentaire