DEV Community

Discussion on: Check if the chain has the same amount

Collapse
 
pbouillon profile image
Pierre Bouillon

Hey @ganeshtata !
I think you missed an uppercase in your elif :)

elif c == "o" or c == "o": 

instead of

elif c == "o" or c == "O": 

To dig a little deeper, I suggest you to see some very useful string methods in Python !

Collapse
 
ganeshtata profile image
Tata Ganesh • Edited

Thank you for that! I had not noticed it. Yes, there are some awesome string methods in Python, but I didn't use any of them here because I wanted to finish the count(s) in one pass of the string. Doing a .lower() and then counting might involve two passes of the same string.

Thread Thread
 
pbouillon profile image
Pierre Bouillon

I suggested it to reduce your conditions, lowering the string before checking would have allowed you to only check for o and x for example. This way you would have one pass on the string and a more concise condition :)

Thread Thread
 
ganeshtata profile image
Tata Ganesh • Edited

Do you mean lowering the string before the loop or lowering the character in the loop before checking whether it is an 'x' or 'o'?

  • Lowering the string before the loop would involve one complete pass of the string. And then you would have to iterate through the string, again, to count the frequencies.
  • Lowering just the character inside the loop, is just equivalent to the if condition, right? I am probably saving on a function call by not calling .lower() on the character.
Thread Thread
 
pbouillon profile image
Pierre Bouillon

Oh right, nevermind !