for x in range(0,len(b)):
if x+1 < len(b):
if b[x][1] == 'B' and b[x+1][1] == 'B':
a.append([b[x][0], b[x][2]])
elif b[x][1] == 'B'and b[x+1][1] == 'I':
kata = b[x][0]
a = 1
while True:
if x+a < len(b):
if b[x+a][1] == 'I':
kata += ' ' + b[x+a][0]
a += 1
elif b[x+a][1] == 'B':
break
else:
break
a.append([kata, b[x][2]])
else:
if b[x][1] == 'B':
a.append([b[x][0], b[x][2]])
Can someone help me to convert the for-loop become while-loop? and the while-loop stay while-loop?
while
loop offers no advantages here. If this is purely for exercise, see my answer below.while
loop into afor
loop:for y in range(x+1, len(b)):
wherey = x+a
...