Rewrite the following program using for loop. lst = ['desert', 'dessert', 'to', 'too', 'lose', 'loose'] s = 'Mumbai' i = 0 while i < len(lst) : if i > 3 : break else : print(i, lst[i], s[i]) i += 1 Solution - clcoding.com/2023/11/rewrit…
@clcoding Here is the code rewritten using a for loop:🎯 lst = ['desert', 'dessert', 'to', 'too', 'lose', 'loose'] s = 'Mumbai' for i in range(4): print(i, lst[i], s[i]) This code will print the following output: 👇 0 desert M 1 dessert u 2 to m 3 too b
@clcoding is it that you want? >>> for i in list(enumerate(zip(lst,s),0)): ... print(i) ... (0, ('desert', 'M')) (1, ('dessert', 'u')) (2, ('to', 'm')) (3, ('too', 'b')) (4, ('lose', 'a')) (5, ('loose', 'i'))
@clcoding shortest code, lst = ['desert', 'dessert', 'to', 'too', 'lose', 'loose'] s = 'Mumbai' print([(i, lst[i], s[i]) for i in range(4)])
@clcoding lst = ['desert', 'dessert', 'to', 'too', 'lose', 'loose'] s = 'Mumbai' for i in range(len(lst)): if i > 3: break else: print(i, lst[i], s[i]) The output of the provided program would be: 0 desert M 1 dessert u 2 to m 3 too b
@clcoding lst = ['desert', 'dessert', 'to', 'too', 'lose', 'loose'] s = 'Mumbai' for i in range(len(lst)): if i > 3: break else: print(i, lst[i], s[i])
@clcoding lst = ['desert', 'dessert', 'to', 'too', 'lose', 'loose'] s = 'Mumbai' for i in range(0, len(lst)): if i > 3: break else: print(i, lst[i], s[i]) ---- this is what i came up with
@clcoding lst = ['desert', 'dessert', 'to', 'too', 'lose', 'loose'] s = 'Mumbai' for i in range(len(lst)): if i > 3 : break else : print(i, lst[i], s[i])
@clcoding For i in range(len(lst)): If i> 3: break else: print(i, lst[i], s[i])