TypeError

    [파이썬] TypeError: list indices must be integers or slices, not str

    x 리스트에서 조건에 맞는 값을 y리스트에 추가 후 출력하려고 하는데 아래와 같은 오류가 발생한다 x = ["grapes", "orange", "apple", "lime", "banana", "cherry", "kiwi", "blueberry", "watermelon"] y = [] for i in x: if (i == "apple") or (i == "kiwi"): y.append(x[i]) print(y) --------------------------------------------------------------------------- y.append(x[i]) ~^^^ TypeError: list indices must be integers or slices, not str TypeError: ..

반응형