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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:41:52+00:00 2026-05-26T15:41:52+00:00

I found myself keep writing pretty long one-liner code(influenced by shell pipe), like this:

  • 0

I found myself keep writing pretty long one-liner code(influenced by shell pipe), like this:

def parseranges(ranges, n):
    """
    Translate ":2,4:6,9:" to "0 1 3 4 5 8 9...n-1"
               == === ==      === ===== =========
    """
    def torange(x, n):
        if len(x)==1:
            (x0, ) = x
            s = 1 if x0=='' else int(x0)
            e = n if x0=='' else s
        elif len(x)==2:
            (x0, x1) = x
            s = 1 if x0=='' else int(x0)
            e = n if x1=='' else int(x1)
        else:
            raise ValueError
        return range(s-1, e)
    return sorted(reduce(lambda x, y:x.union(set(y)), map(lambda x:torange(x, n), map(lambda x:x.split(':'), ranges.split(','))), set()))

I felt ok when I written it.
I thought long one-liner code is a functional-programming style.
But, several hours later, I felt bad about it.
I’m afraid I would be criticized by people who may maintain it.
Sadly, I’ve get used to writing these kind of one-liner.
I really want to know others’ opinion.
Please give me some advice. Thanks

  • 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-26T15:41:52+00:00Added an answer on May 26, 2026 at 3:41 pm

    (Update 2022-03-25: My answer refers to a previous revision of the question.)

    The first and third examples are acceptable to me. They are close enough to the application domain so that I can easily see the intention of the code.

    The second example is much too clever. I don’t even have an idea about its purpose. Can you rewrite it in maybe five lines, giving the variables longer names?

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

Sidebar

Related Questions

I've found myself writing for(int i=0;i<myvec.size();i++) myvec[i]->DoWhatever(param); a lot, and I'd like to compress
I recently found myself writing a piece of code that executed a Core Data
I have found myself doing this in my code to 'cache' the work done
I find myself writing this class often in my python code when I need
I found myself writing the following a lot: int location =2; vector<int> vec; vector<int>::iterator
I have found myself writing the same view over and over. It is basically
This seems like a very simple question, but I've only found complicated answers. I've
I prefer to use long identifiers to keep my code semantically clear, but in
Found myself trying to find a link to an official definition of this design
Been looking at this code for too long and I am getting gloomy any

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.