+ 1
How to solve this problem?
the code, sentence=[['this','is','beautiful','and','nice','place'],['nice','place']] adjective=['beautiful','nice'] freq={} a=1 for sent in sentence: for x in sent: if x in adjective: freq [a]={} freq [a][x]=sent.count (x) a+=1 print (freq) the output I'm getting is, {1:{'nice':1},2:{'nice':1}} bt i need the following output, {1:{'beautiful':1},{'nice':1},2:{'nice':1}}
2 Antworten
+ 3
for sent in sentence:
freq [a]={}
for x in sent:
if x in adjective:
freq [a][x]=sent.count (x)
a+=1
You tossed your result
+ 2
Thank you sir😊