Convert From For-loop And While-loop To While-loop And While Loop Python
for x in range(0,len(b)): if x+1 < len(b): if b[x] == 'B' and b[x+1] == 'B': a.append([b[x], b[x]]) elif b[x] == 'B'and b[x+1] == 'I': kata = b[x] a = 1 while True: if x+a < len(b): if b[x+a] == 'I': kata += ' ' + b[x+a] a += 1 elif b[x+a] == 'B': break else: break a.append([kata, b[x]]) else: if b[x] == 'B': a.append([b[x], b[x]])
Can someone help me to convert the for-loop become while-loop? and the while-loop stay while-loop?
for loop of the form
for x in y: #code
can always be turned into a
while loop of the form
i=0 while i < len(y): x = y[i] #code i += 1
x in your case is just iterating through values
len(b) you can further reduce it down to:
x=0 while x < len(b): #code x += 1
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module