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 9148649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:19:56+00:00 2026-06-17T11:19:56+00:00

here is my code I define an empty set, I want to compare se([i])

  • 0

here is my code
I define an empty set, I want to compare
se([i]) > 0, then reassign the value of se([i]) to be 0. I am not able to do this
since se([i]) is a set and cannot be compared to int. kindly help. I am new to python programming.

se =set()
se.update([8])
print (se)
for i in range (10):
    se.update([i])
    print type(se)
    print len(se)
print se
  • 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-17T11:19:56+00:00Added an answer on June 17, 2026 at 11:19 am

    If you’re just trying to compare each element of se to 0, and replace the ones that are > 0 with 0, that’s pretty easy:

    se = {0 if element > 0 else element for element in se}
    

    Or, if you think about it:

    se = {min(element, 0) for element in se}
    

    You can’t do this by indexing se[i], because sets aren’t indexable, because the whole point of sets (both mathematical and Python) is that they’re unordered. And you definitely can’t do it by calling se([i]), because you sets aren’t functions, or other callable (function-like) things. If you really wanted to do it by mutating in place, you could:

    for element in se.copy():
        if element > 0:
            se.remove(element)
            se.add(0)
    

    (Notice the se.copy() there—you can’t change the shape of a collection while iterating over it, so you need to iterate over a copy of it instead.)

    Meanwhile, again, the whole point of a set is that it’s unordered, which means adding 0 multiple times is exactly the same as adding it once. So:

    >>> se = { -3, -2, -1, 0, 1, 2, 3 }
    >>> print se
    set([0, 1, 2, 3, -1, -3, -2])
    >>> se = {min(element, 0) for element in se}
    >>> print se
    set([0, -2, -3, -1])
    

    Or, using your code (with some of the extra print statements removed for brevity):

    >>> se =set()
    >>> se.update([8])
    >>> print (se)
    set([8])
    >>> for i in range (10):
    ...     se.update([i])
    >>> print se
    set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
    >>> se = {min(element, 0) for element in se}
    >>> print se
    set([0])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code I use to define my array, this code is above
Here is my code: #include <stdio.h> #include <string.h> #include <windows.h> #include <tchar.h> #define MAX_KEY_LENGTH
Here is some C++ code I'm playing around with: #include <iostream> #include <vector> #define
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is my code: #Check if the value has only allowed characters def checkStr(value):
Here is the code: //Note: x actually isn't defined, I'm pulling it from an
Here is the code, I defined two class named Father and Son, and create
I have an image in my code, as defined here var imageObj = new
The script is on jsfiddle here : CODE What it does at the moment
Here is code my jqgrid editing through form. $(#DataEnergy).jqGrid('navGrid', '#pagergrid', {}, //options {editdata: {

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.