+ 1

Can you write a code? How to select odd words in a sentence and sort them?

I must select odd words in a sentence and sort them. For example, sentence :"Hello, my dear friends. How are you?"

5th Dec 2020, 8:49 PM
Марина
Марина - avatar
6 Answers
+ 2
What are odd words in your example? And your try?
5th Dec 2020, 9:34 PM
Jayakrishna 🇮🇳
+ 2
🌸littlє__chєrrч🌸Well, i wrote such code, but i must write other method text = " Hello my dear friends. How are you? " c = len(text.split()) print(c) v = text.split() b = "" for i in range(0, c): if i % 2 == 0: b = b + v[i] + " " b = b.split() b = sorted(b,key = lambda x: x[-1]) b = ' '.join(b) print(b)
5th Dec 2020, 9:38 PM
Марина
Марина - avatar
+ 2
Jayakrishna🇮🇳 well, Odd words: Hello dear how you. I must chose this words and sort it
5th Dec 2020, 9:39 PM
Марина
Марина - avatar
+ 2
Jayakrishna🇮🇳 ,yeah, thank you very much 🙏🙏
5th Dec 2020, 10:10 PM
Марина
Марина - avatar
+ 1
Марина other method means..! Is this OK? text = " Hello my dear friends. How are you? " v = text.split()[0::2] v.sort() print(' '.join(v))
5th Dec 2020, 9:48 PM
Jayakrishna 🇮🇳
+ 1
Марина you're welcome...
6th Dec 2020, 10:32 AM
Jayakrishna 🇮🇳