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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:43:17+00:00 2026-06-11T02:43:17+00:00

Possible Duplicate: Line continuation for list comprehensions or generator expressions in python What is

  • 0

Possible Duplicate:
Line continuation for list comprehensions or generator expressions in python

What is the the most pythonic way to write a long list comprehension? This list comprehension comes out to 145 columns:

memberdef_list = [elem for elem in from_cache(classname, 'memberdefs') if elem.argsstring != '[]' and 'std::string' in null2string(elem.vartype)]

How should it look if I break it into multiple lines? I couldn’t find anything about this in the Python style guides.

  • 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-11T02:43:19+00:00Added an answer on June 11, 2026 at 2:43 am

    PEP 8 kinda predates list comprehensions. I usually break these up over multiple lines at logical locations:

    memberdef_list = [elem for elem in from_cache(classname, 'memberdefs')
                      if elem.argsstring != '[]' and 
                         'std::string' in null2string(elem.vartype)]
    

    Mostly though, I’d forgo the involved test there in the first place:

    def stdstring_args(elem):
        if elem.argstring == '[]':
            return False
        return 'std::string' in null2string(elem.vartype)
    
    memberdef_list = [elem for elem in from_cache(classname, 'memberdefs')
                      if stdstring_args(elem)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why do people write #!/usr/bin/env python on the first line of a
Possible Duplicate: python: how to jump to a particular line in a huge text
Possible Duplicate: What's the best way to grab/parse command line arguments passed to a
Possible Duplicate: Learn Python the Hard Way Exercise 17 Extra Question(S) In this exercise
Possible Duplicate: How to get line count cheaply in Python? Good day. i have
Possible Duplicate: Best way to parse command line arguments in C#? What's the best
Possible Duplicate: Add a line to a file if it not exist using python
Possible Duplicate: Xcode 4 with opening brace on new line Is there a way
Possible Duplicate: php - efficent way to get and remove first line in file
Possible Duplicate: In C++ is there a way to go to a specific line

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.