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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:39:24+00:00 2026-05-23T10:39:24+00:00

Ref: python decompose a list Flattening a shallow list in Python While the above

  • 0

Ref:
python decompose a list
Flattening a shallow list in Python

While the above mentioned solutions are helpful, my problem is slightly different, and I was wondering if there is a pythonic way to solve it.

a = [['a-3','b-3'],'r',['j']]

What I would like, is a clean way of making ‘a’ equal the following:

a = ['a-3','b-3','r','j']

I am stuck using python 2.4 so a pythonic solution that’s 2.4 compatible would be great, but I would still find 2.7+ examples interesting as well.

The main problem is that there are non-iterable elements, otherwise the sum(lst,[]) works quite well, as does the chain method for 2.7+

  • 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-23T10:39:24+00:00Added an answer on May 23, 2026 at 10:39 am

    Pythonic solution can mean many thing. With readability counts (PEP 20) in mind, this is my contribution to the thread:

    def dec(input_, output_):
        if type(input_) is list:
            for subitem in input_:
                dec(subitem, output_)
        else:
            output_.append(input_)
    

    Example:

    input_ = [['a-3','b-3', ['x','hello', ['3','b']]],'r',['j']]
    output_ = ['a-3', 'b-3', 'x', 'hello', '3', 'b', 'r', 'j']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Inverse dictionary lookup - Python If I have a dictionary named ref
I'm using MySQLdb library to connect to MySQL within my Python script. (Ref: http://mysql-python.sourceforge.net/MySQLdb.html
Ref. to my last post and sellibitze's comment to that post on passing array
public ref class ScriptEditor : public Form { public: typedef map<UInt32, ScriptEditor^> AlMap; static
Is Interlocked.Increment(ref x) faster or slower than x++ for ints and longs on various
The documentation for ref() mentions several possible return values. I understand most of them,
public object MethodName(ref float y) { // elided } How do I define a
What is the difference between ref and out parameters in .NET? What are the
What's the difference between java.lang.ref.WeakReference and java.lang.ref.SoftReference ?
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup I can think of a few ways of doing it with loops but

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.