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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:53:32+00:00 2026-05-15T01:53:32+00:00

I noticed a problem when I was trying to use del in a lambda

  • 0

I noticed a problem when I was trying to use del in a lambda to thin out a list of threads to just those running:

map(lambda x: del(x) if not x.isAlive() else x, self.threads)

Ignore for a second that this doesn’t do anything, I’m just fooling around with map, reduce, and lambda.

This fails with a syntax error at del(x). With some messing around, I think the problem is del() doesn’t return a value. For example, this fails with the same error:

b = 5
x = del(b)

This doesn’t, however:

def rmThis(x): del(x)

Which means I’m using this workaround:

map(lambda x: rmThis(x) if not x.isAlive() else x, self.threads)

So is the limitation just because del() doesn’t return a value? Why not?

I’m using python 2.6.2

  • 1 1 Answer
  • 2 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-05-15T01:53:33+00:00Added an answer on May 15, 2026 at 1:53 am

    Two problems. The first one is more subtle so I’ll explain that first.

    The issue is that del removes a variable binding. Passing it a value will not serve your purpose.

    Here’s an illustration

    >>> a = 5
    >>> del(a)
    >>> a
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'a' is not defined
    >>> def mydel(x): del(x)
    ... 
    >>> a = 5
    >>> mydel(a)
    >>> a
    5
    >>> 
    

    As you can see. In the first case, the variable a has been removed from the current namespace. There’s no way to refer to the object it pointed to anymore (assuming nothing else points to the same thing).

    In the second case, you are not removing a from the namespace. You are deleting the binding of x in the function namespace the effect of which is that you won’t be able to use x as as an rvalue anymore in the function (ie. it’s an undefined variable).

    The second problem is the SyntaxError which is simpler. Python lambda functions can only have expressions in them and not statements. del in not an expression (i.e., not a function call) – it’s a statement (the del_stmt) and so it can’t appear in the body of the lambda. You’d see the same issue if you tried putting a print in the body of the lambda.

    >>> lambda x: print x
      File "<stdin>", line 1
        lambda x: print x
                      ^
    SyntaxError: invalid syntax
    

    This also accounts for why the x=del(a) fails. The statement syntax is invalid. It’s not a function that can be called.

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

Sidebar

Related Questions

While trying to troubleshoot a problem I'm having with a project, I noticed that
I'm surely not the first one noticed the problem below: when using the graphical
Not a problem as such but during development I noticed that Chrome doesn't accept
I'm trying to use Apache Commons Net for FTP file transfers. Problem is files
I'm trying to figure out why this is a problem when using jQuery 1.4.2
I'm running into a problem with the Symfony2 Security system, particularly when trying to
I've noticed that when trying to use superscript or subscript in the following way...
I've noticed this problem when trying to insert a node before an empty element
I've noticed some problem with va_start when call successively in two functions. A basic
I was playing around with forms authentication and I noticed a problem if the

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.