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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:45:39+00:00 2026-05-14T07:45:39+00:00

I want to filter elements from a list of lists, and iterate over the

  • 0

I want to filter elements from a list of lists, and iterate over the elements of each element using a lambda. For example, given the list:

a = [[1,2,3],[4,5,6]]

suppose that I want to keep only elements where the sum of the list is greater than N. I tried writing:

filter(lambda x, y, z: x + y + z >= N, a)

but I get the error:

 <lambda>() takes exactly 3 arguments (1 given)

How can I iterate while assigning values of each element to x, y, and z? Something like zip, but for arbitrarily long lists.

thanks,

p.s. I know I can write this using: filter(lambda x: sum(x)…, a) but that’s not the point, imagine that these were not numbers but arbitrary elements and I wanted to assign their values to variable names.

  • 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-05-14T07:45:39+00:00Added an answer on May 14, 2026 at 7:45 am

    Using lambda with filter is sort of silly when we have other techniques available.

    In this case I would probably solve the specific problem this way (or using the equivalent generator expression)

    >>> a = [[1, 2, 3], [4, 5, 6]]
    >>> [item for item in a if sum(item) > 10]
    [[4, 5, 6]]
    

    or, if I needed to unpack, like

    >>> [(x, y, z) for x, y, z in a if (x + y) ** z > 30]
    [(4, 5, 6)]
    

    If I really needed a function, I could use argument tuple unpacking (which is removed in Python 3.x, by the way, since people don’t use it much): lambda (x, y, z): x + y + z takes a tuple and unpacks its three items as x, y, and z. (Note that you can also use this in def, i.e.: def f((x, y, z)): return x + y + z.)

    You can, of course, use assignment style unpacking (def f(item): x, y, z = item; return x + y + z) and indexing (lambda item: item[0] + item[1] + item[2]) in all versions of Python.

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

Sidebar

Related Questions

I have got some lists, and I want to filter elements from them. Here's
I want to filter repeated elements in my list for instance foo = ['a','b','c','a','b','d','a','d']
I want to select elements from myCollection using myFilters for filtering: var myFilters =
Suppose I have a List[Int] , and I want to call toString on each
I want to choose an element and then remove it from a mutable list
Well this is a simple question i want to filter two elements sorted reverse
I want to go through the children of an element and filter only the
I want to filter my model object using two filters. So, it can be
I want to filter rows from a data.frame based on a logical condition. Let's
In my List, I want to ignore certain entries(create list filter), by ignore I

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.