[Python] Finding if a value is found within a list in python

Discussão em 'Python' iniciado por Stack, Junho 27, 2025.

  1. Stack

    Stack Membro Participativo

    My code is something like

    aList = ['apple', 'banana', 'cherry']
    anotherList = ['orange', 'apple', 'blueberry']
    adifferentList = ['strawberry', 'pear', 'peach']
    aSet = [aList, anotherList, adifferentList]
    for i in a set:
    if i.index("apple"):
    temp = i.index("apple")
    del i[temp]
    else:
    pass


    I was hoping that if a list doesn't contain "apple" it will just pass but it is currently erroring with that the list does not contain that value. Be gentle, I've taken a quarter of coding.

    Edit: Error is as follows


    ValueError: 'apple' is not in list
    ​

    Continue reading...

Compartilhe esta Página