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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:02:02+00:00 2026-06-06T14:02:02+00:00

The original code was somehow complex, i simplify it as: Given: list of class

  • 0

The original code was somehow complex, i simplify it as:

Given:

  1. list of class instance, e.g.: l=[c1,c2,c3, …]
  2. each instance has a member variable list, e.g. c1.memList=[3,2,5], c2.memList=[1,2]

Todo:
select those instances in l, whose memList has only ‘3’-modulo item , e.g, c3.memList=[3,6,9,3,27]

I thought to code it like this:

newl = [ n for n in l if len( [m for m in n.memList if m%3] )==0 ]

But: list comprehension does not allow this by saying ‘m is not defined’

Question: how to code this in a pythonic way?

New edit: Sorry I made a typo (mistyped if to in), it worked. I will propose to close this question.

  • 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-06T14:02:06+00:00Added an answer on June 6, 2026 at 2:02 pm

    I did not get any Error concerning ‘m is not defined’ the reasons must be outside of this snippet.

    newl = [ n for n in l if all([ m % 3 == 0  for m in n.memList]) ]
    

    I would recommend something like this, the all() function improves readability. It is allways good to use the list Syntax cause it speeds calculations.

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

Sidebar

Related Questions

The original code: public List<Contact> GetContactListEntityCompiledLINQ() { if (entities == null) entities = new
----Complete Rephrasing---- I was working on a new class where each instance was essentially
The original code looks like this: module Acme class Address STREET_NAME = 123 acme
here is the original code: public static int getInt () { Scanner in =
I have a plugin where the original code is ... // when the DOM
I need to migrate some C# code to Python. The original code makes use
The code below is (hopefully) a minimized testcase of my original problem. I'm trying
from this code will show in original color how can i change it to
Can I install code analysis in VSTS2008 SP1 without the original installation media? Is
I want to generate Javascript code from an existing Java project ( original question

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.