ok
I will take care of it.
but i this problem i am not able reverse the the particular word
in doing so my whole sentence is reversing.
plzz help i am not getting solution
Try not to post whole code solutions here, there is no way of flag them as spoilers and are shown on the Home's Discussion block. Discussion about a particular kata solution belongs on that challenge solutions tab (they're only visible to people that already solved that kata). Thanks.
def spin_words(sentence):
# Your code goes here
word = ""
sen = ""
for i in sentence:
if i != " ":
word = word + i
if len(word) >= 5:
r1 = word[::-1]
sen = sen + r1
else:
sen = sen + word
def spin_words(sentence):
# Your code goes here
word = ""
sen = ""
for i in sentence:
if i != " ":
word = word + i
if len(word) >= 5:
r1 = word[::-1]
sen = sen + r1
else:
sen = sen + word
Hi, I did the Valid Parentheses challenge, where you're supposed to write a function that tells whether a bunch of parentheses are grouped together correctly. () should be true, )( should be false, ()) should be false, etc. I solved the challenge, but I like to look at other peoples' answers to see how I could've done better. I don't understand how the top answer works successfully.
Here is the code:
function validParentheses(parens){
var indent = 0;
for (var i = 0 ; i < parens.length && indent >= 0; i++) {
indent += (parens[i] == '(') ? 1 : -1;
}
return (indent == 0);
}
When I try to think through it, it seems like the code would return )()( as true, even though it's false. However, when I ran the code it correctly returned it as false. Can someone explain to me how the code works so that the proper result is returned in this case?
Post in that kata discussion, also without code formatting (check code block in the link) https://github.com/Codewars/codewars.com/wiki/Markdown-Formatting Python code is not readable.
ok
I will take care of it.
but i this problem i am not able reverse the the particular word
in doing so my whole sentence is reversing.
plzz help i am not getting solution
Try not to post whole code solutions here, there is no way of flag them as spoilers and are shown on the Home's Discussion block. Discussion about a particular kata solution belongs on that challenge solutions tab (they're only visible to people that already solved that kata). Thanks.
Take a look at the loop condition, it exits if indent is less than 0.
def spin_words(sentence):
# Your code goes here
word = ""
sen = ""
for i in sentence:
if i != " ":
word = word + i
if len(word) >= 5:
r1 = word[::-1]
sen = sen + r1
else:
sen = sen + word
def spin_words(sentence):
# Your code goes here
word = ""
sen = ""
for i in sentence:
if i != " ":
word = word + i
if len(word) >= 5:
r1 = word[::-1]
sen = sen + r1
else:
sen = sen + word
Hi, I did the Valid Parentheses challenge, where you're supposed to write a function that tells whether a bunch of parentheses are grouped together correctly. () should be true, )( should be false, ()) should be false, etc. I solved the challenge, but I like to look at other peoples' answers to see how I could've done better. I don't understand how the top answer works successfully.
Here is the code:
function validParentheses(parens){
var indent = 0;
for (var i = 0 ; i < parens.length && indent >= 0; i++) {
indent += (parens[i] == '(') ? 1 : -1;
}
return (indent == 0);
}
When I try to think through it, it seems like the code would return )()( as true, even though it's false. However, when I ran the code it correctly returned it as false. Can someone explain to me how the code works so that the proper result is returned in this case?