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

  • Home
  • SEARCH
  • 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 8217513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:29:23+00:00 2026-06-07T12:29:23+00:00

I was wondering what the neatest way would be to convert (from Python) a

  • 0

I was wondering what the neatest way would be to convert (from Python) a list comprehension into Javascript. Is there anything which will make this readable and not a mess?

    non_zero_in_square = [ grid[row][col]
                           for row in range(start_row, start_row+3)
                           for col in range(start_col, start_col+3)
                           if grid[row][col] is not 0
                         ]

This is quite a good example of a list comprehension, as it has multiple fors and and an if.

I should add that the range bit is covered here (I can’t live without range).

  • 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-07T12:29:24+00:00Added an answer on June 7, 2026 at 12:29 pm

    Well it would be somewhat messy to do this with the .map() method, because the outer calls really need to return arrays. Thus you’re probably best with the pedestrian:

    var nonZero = [];
    for (var row = startRow; row < startRow + 3; ++row)
      for (var col = startCol; col < startCol + 3; ++col)
        if (grid[row][col] !== 0) nonZero.push(grid[row][col];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wondering if there is any way to get the lambda expressions that result from
Wondering if there is a fast way, maybe with linq?, to convert a Dictionary<string,string>
Wondering if there is a way to use a python script to attempt a
In Python 2.2 (don't ask), what's the neatest way to sort a list and
Wondering what the best / good way of doing this would be in jQuery.
Wondering if there is a good way to generate temporary URLs that expire in
Wondering whether there is an efficient way to add an item to Java's ArrayList
Wondering what would be the most efficient way to do the following. Game play.
Wondering if there is any way to build and fire an event (e.g. on
Wondering if there’s a plugin or best way of setting up an ActiveRecord class

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.