N
N
NotCoolProgrammer2021-12-09 20:16:20
Python
NotCoolProgrammer, 2021-12-09 20:16:20

How to display all words of a string containing an odd number of letters relative to the center of the word?

Task: given a string of characters consisting of individual words separated by a space. Output all words of a string containing an odd number of letters relative to the center of the word. All that I could write (still with an error):

a = input("Enter symbols: ").split()
b = []
for i in a:
    if (len(a[i])) %2 != 0:
        b.append(i)
print(b)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-12-09
@NotCoolProgrammer

for i in a:
If you apply the for statement to a list, it enumerates the elements of the list, not the indices.
So not len(a[i]) but len(i)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question