A reader asked the following question:
I’ve noticed that you use range objects with for loops to iterate over strings. Why don’t you use a regular for loop instead? ie. why not do this:
for c in input_str: stack.push(c)
instead of:for i in range(len(input_str): stack.push(input_str[i])
First of all, in response to “Why don’t you use a regular for loop instead?”, I’d say that it is not correct to refer to your version as a “regular for loop” Both implementations involve the “regular for loop” structure. Secondly, you can use the “for c in input_str”. Both implementations, in this case, will yield identical results. If you prefer the latter implementation, that’s fine too. Hope this helps!
Best Regards,
Alina Fatima | Developer Advocate