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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:18:41+00:00 2026-05-22T01:18:41+00:00

I have a nodelist object that yields a bunch of node objects on iteration.

  • 0

I have a nodelist object that yields a bunch of node objects on iteration. I need to increment these nodes based on some random condition (like node.x > 17). Here’s what I’m doing right now:

for node in nodelist: 
    if node.x > 17: 
        node.x += 1 

I can’t do map(lambda node: node.x += 1, nodelist) because lambda can’t contain assignment. I cannot do nodelist = [node.x + 1 for node in nodelist if...] because a nodelist object consists of more than just its child nodes.

Is there a way to make this shorter/cleaner?

  • 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-22T01:18:42+00:00Added an answer on May 22, 2026 at 1:18 am

    I think it’s already pretty short and clean. Python provides some powerful tools, but sometimes simple is best; this seems like one of those times.

    I also think what you have is more readable than any equivalent one-liner (that I can come up with).


    Ok, that said, you could do this:

    for node in (n for n in nodelist if condition):
        node.x += 1
    

    That could even be compressed into one line. But I honestly prefer the way you have it now.

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

Sidebar

Related Questions

I have a Javascript function that accepts a list of HTML nodes, but it
I need to have my PHP extension return an array of objects, but I
Hi I have 2 classes in Java, Gossip and Node , I want that
So I have some perl code that goes something like: use strict; use XML::XPath;
I have this code: Node main_node = document.getDocumentElement(); NodeList main_node_list = main_node.getChildNodes(); for( int
I need to create a XML Document object using the NodeList. Can someone pls
I have a xml with the following structure: <NODES> <NODE> <NAME> </NAME> <IMG> </IMG>
I have 1 activity that receives a json object from the server (database) and
I have defined a class that contains properties of a specific answer object The
I have a set of objects in a hierachy. There's a top root node

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.