Why doesn't the code select odd words? And how do i sort them in descending order of the word? | SoloLearn: Learn to code for FREE!

+7

Why doesn't the code select odd words? And how do i sort them in descending order of the word?

text = " Hello, my dear friends. How are you?" for i in text. split(): if text. index(i) % 2 == 0: print(i)

10/14/2020 7:21:53 PM

Марина

43 Answers

New Answer

+31

Clara Chloe Perhaps "PITHON" is a new programming language. A similar programming language is "PHYTON", which is also often mentioned. And now I suggest a further new programming language: 🕊 P I G E O N 🕊

+13

# corrected code: text = " Hello, my dear friends. How are you?" t2 = text.split() for i in t2: if t2.index(i) % 2 != 0: print(i)

+9

# also possible: text = " Hello, my dear friends. How are you?" for i,j in enumerate(text.split()): if i&1: print(j)

+7

Frogged I did implement the mistake on purpose in order to you having the chance to correct me. 😁🌿

+7

Jan Markus I suggest 'PITON' as a new name. It's not funny but less confusing 🤪 I still can't pronounce 'th' sounds properly 😂🤣 Марина вопрос можно редактировать сколько угодно. Нужно нажать кнопку меню в правом верхнем углу.

+6

# more elegant: text = " Hello, my dear friends. How are you?" for i,j in enumerate(text.split()): if i % 2 != 0: print(j)

+6

You are welcome! 🙂👍

+5

Jan Markus ohh yes sure... Finally it was a test from Марина if we find that issue. She is a recruiter for a big consultant company and looking for new talents. ☺️

+5

Frogged Unfortunately, i am just student. And it is my homework😂

+4

# and a further one: text = " Hello, my dear friends. How are you?" l = text.split() print(*[l[i] for i in range(1,len(l),2)], sep='\n')

+4

Марина which 2 do not work? 🤔

+4

but they all print the even ones🤔🤔🤔🤔

+4

Марина all secret recruiter say that😂 btw.... odd or even?

+4

words = text. split() oddwords = [words[i] for i in range(1,len(words),2)]

+4

Jan Markus have already helped ✌️ Sorry to say, but 'python' spelling in question is incorrect 😅✌️.

+3

Odd words are words with odd length or odd order(index) in text?

+3

So AI FOLKS..... Assign words to programing languages. Given a post. Find out, if programming language is mentioned and replace by correct spelling. Eg Can i lern jascip -->Javascript

+2

Russ thank you

+1

Jan Markus thank you very much 🤗Unfortunately, 2 codes doesn't work.

+1

Jan Markus everything is working now. Thank you very much 🤗