Reputation: 5
for x in a:
if x[1] in NERTagger:
kata = ''
kt = NERTagger[x[1]]
for y in a:
if x[0] is not y[0]:
kata += y[0] + ' '
elif x[0] == y[0]:
kata += kt + ' '
hasil.append(kata)
How to transform the code above into the while-loop? because there is an if and for-loop again in the code
Upvotes: 0
Views: 868
Reputation: 5
There's no problem in using nested for
functions.
while
is just a general form of for
:
for
does 3 things:
while
does 1 of these: sets a stop condition.
Upvotes: 0
Reputation: 3318
i = 0
while i < len(a):
x = a[i]
i = i + 1
if x[1] in NERTagger:
kata = ''
kt = NERTagger[x[1]]
j = 0
while j < len(a):
y = a[j]
if x[0] is not y[0]:
kata += y[0] + ' '
elif x[0] == y[0]:
kata += kt + ' '
j = j+1
hasil.append(kata)
Upvotes: 2