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

  • SEARCH
  • Home
  • 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 8841295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:40:47+00:00 2026-06-14T10:40:47+00:00

i have a list , lets say : test = [False, False, 2, False,

  • 0

i have a list , lets say :

test = [False, False, 2, False, False, False, 3, False, False]

and i want to assign every member of this list to False unless this member is equal to 2
so the result should be :

test = [False, False, 2, False, False, False, False, False, False]

i tried :

test = [False for i in test if i !=2]

but the result was :

[False, False, False, False, False, False, False, False]

and i try to define a function :

def set_False(lst):
     for i in lst:
         if i != 2:
            i = False
    return lst

and when i apply :

test = set_False(test)

the result was:

[False, False, 2, False, False, False, 3, False, False]

i can’t use enumerate in the environment where i am putting my code , so any suggestion ?

thanks

  • 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-14T10:40:48+00:00Added an answer on June 14, 2026 at 10:40 am

    It’s

    [False if i !=2 else 2 for i in test]
    

    Otherwise, you’re skipping the whole element when it’s equal to 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say that I have a list list = ['this','is','just','a','test'] how can I have
Lets say I have this code: public void MyMethod(string Data, List<string> InputData) { //I
Lets say I have this list: lst = [[0], [0, 0], [0, 0, 0],
I have a list of items lets say for example a, b, c. As
Lets say I have a list: L = [15,16,57,59,14] The list contains mesurements, that
Lets say I have a list of 1,000,000 users where their unique identifier is
Lets say i have the following unordered list <ul> <li><a>Hank</a></li> <li><a>Alice</a></li> <li><a>Tom</a></li> <li><a>Ashlee</a></li> </ul>
Lets Say i have a table like this WEB_LIST_TABLE KEY Value ---------------------------------------- 134 google.com
Lets say a have the following Model public class FirstModel { public List<SecondModel> SecondModels
Lets say I have a database of widgets. I am showing a list of

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.