+ 2

How did you approach this challenge?

I just solved the flowing words in code coach. I'm self-taught so I don't get feedback on my code. I really appreciate your input and feedback how to improve my code and how you approached this challenge. Thanks in advance :) https://code.sololearn.com/cYTYFSqCWE34/?ref=app

17th Oct 2023, 8:37 AM
J C
8 Réponses
+ 6
J C , i have done a try how we can select the required words and letters. maybe it can help you: https://code.sololearn.com/cEMqP4qOYkd8/?ref=app
17th Oct 2023, 7:39 PM
Lothar
Lothar - avatar
+ 3
You would split the words into an list, then compare last character from the first word to the first character of the second word.
17th Oct 2023, 8:48 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 3
Thanks for the feedback! I have thought of that first before I got to my solution, although I don't know how to code your suggestion yet at this point. I would love to see your code or get a hint on how to do that though. :)
17th Oct 2023, 9:11 AM
J C
+ 3
Here is the hint if you need it. Use split() method to split the string into a list. You have to call each item by their index, instead of "for item in list", use "for i in length of something". Make use of the index. Make a check if are you calling an out or range index, if it happens, plan your exit. It will look nicer with a user defined function, although it is not necessary.
17th Oct 2023, 10:16 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 2
J C, if you thought of that before, why not post your attempted code here? It doesn't matter the code work or not. After looking at your code then we can guide you where to look.
17th Oct 2023, 9:48 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 2
Thanks for the hint. What I was thinking was to use a sliding window to the list to grab 2 words at a time like this: text = input().split() for i in range(len(text)-1): print(text[i:i+2]) I googled the for loop and modified it to fit in the code. Though I'm confused how to compare the last letter of the first word from the first letter for the next word. Should I just store the different values in 2 separate variables and compare using if-else or is there a better way? Or am I approaching this the wrong way? Hehe
17th Oct 2023, 10:38 AM
J C
+ 2
Ahh. I see. I'll try this one out. Thanks a lot 🙏 :)
17th Oct 2023, 11:41 AM
J C
+ 1
Your code grabs a pair, but your goal is to compare the element inside the pair. For a starter, you can store the 1st word into a variable, and 2nd into another variable, and work your comparison from there. A more advance technique, you can search for "python addressing nested list". Although it is not covered in the material in here, the same concept applies. And try to think in the opposite way.
17th Oct 2023, 11:15 AM
Wong Hei Ming
Wong Hei Ming - avatar