Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7783671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:54:22+00:00 2026-06-01T19:54:22+00:00

I know that the and and or expressions exist in python, but is there

  • 0

I know that the and and or expressions exist in python, but is there any and/or expression? Or some way to combine them in order to produce the same effect as a and/or expression?

my code looks something like this:

if input=="a":        
    if "a" or "á" or "à" or "ã" or "â" in someList:            
        someList.remove("a") or someList.remove("á") or someList.remove("à") or someList.remove("ã") or someList.remove("â")

with this, I mean that if the user inputs “a” and any type of “a” is included in a previously defined list, can I have all the types of “a” removed from a given list?

python tells me that there is a problem in:

someList.remove("a") or someList.remove("á") or someList.remove("à") or someList.remove("ã") or someList.remove("â")

he tells me: ValueError: list.remove(x): x not in list

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:54:23+00:00Added an answer on June 1, 2026 at 7:54 pm

    As Matt Ball‘s answer explains, or is “and/or”. But or doesn’t work with in the way you use it above. You have to say if "a" in someList or "á" in someList or.... Or better yet,

    if any(c in someList for c in ("a", "á", "à", "ã", "â")):
        ...
    

    That’s the answer to your question as asked.

    Other Notes

    However, there are a few more things to say about the example code you’ve posted. First, the chain of someList.remove... or someList remove... statements here is unnecessary, and may result in unexpected behavior. It’s also hard to read! Better to break it into individual lines:

    someList.remove("a")
    someList.remove("á")
    ...
    

    Even that’s not enough, however. As you observed, if the item isn’t in the list, then an error is thrown. On top of that, using remove is very slow, because every time you call it, Python has to look at every item in the list. So if you want to remove 10 different characters, and you have a list that has 100 characters, you have to perform 1000 tests.

    Instead, I would suggest a very different approach. Filter the list using a set, like so:

    chars_to_remove = set(("a", "á", "à", "ã", "â"))
    someList = [c for c in someList if c not in chars_to_remove]
    

    Or, change the list in-place without creating a copy:

    someList[:] = (c for c in someList if c not in chars_to_remove)
    

    These both use list comprehension syntax to create a new list. They look at every character in someList, check to see of the character is in chars_to_remove, and if it is not, they include the character in the new list.

    This is the most efficient version of this code. It has two speed advantages:

    1. It only passes through someList once. Instead of performing 1000 tests, in the above scenario, it performs only 100.
    2. It can test all characters with a single operation, because chars_to_remove is a set. If it chars_to_remove were a list or tuple, then each test would really be 10 tests in the above scenario — because each character in the list would need to be checked individually.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that in Lisp a list must end with nil, but expression like
I know the conditional expression in Python is X if C else Y, but
I know that lot of questions about HTML sanitizers have appeared in SO, but
I know that all of these will be compiled together into one file but
I know that a powerset is simply any number between 0 and 2^N-1 where
I know that when linking to multiple static libraries or object files, the order
I know that similar question was asked several times, but still I can't make
The Python docs say that * and / have the same precedence. I know
Is there any overhead associated with using lambda expressions in C++0x (under VS2010)? I
I need to understand bash if expressions. Sure, I've used Google. I know that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.