@
@
@calpy2018-10-19 22:43:19
Python
@calpy, 2018-10-19 22:43:19

Why is the list object not the same as its index?

glasn = ["e", "u", "i", "o", "y", "a"]


def transkrip():
    slovo = input("Введите слово: ")
    list_slova = list(slovo)
    for x in list_slova:
        if x in glasn:
            len_glasn = glasn.index(x) 
            s = str(len_glasn) + " - " + x # обьект списка не совпадает с его индексом
            print(s)

For example, when you enter the word "hello" it will give:
0 - e
3 - o

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2018-10-19
_

The index is counted from zero:

["e", "u", "i", "o", "y", "a"]
  0    1    2    3    4    5

Everything seems to be as it should be. What confuses you?

X
x_dmitry_x, 2018-10-20
@x_dmitry_x

#...
len_glasn = list_slova.index(x)
#...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question