+ 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?"
7 ответов
+ 2
What are odd words in your example?
And your try?
+ 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)
+ 2
Jayakrishna🇮🇳 well, Odd words: Hello dear how you. I must chose this words and sort it
+ 2
Jayakrishna🇮🇳 ,yeah, thank you very much 🙏🙏
+ 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))
+ 1
Марина you're welcome...