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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:36:24+00:00 2026-06-14T03:36:24+00:00

So I have several lists that are the headers of variables in a data

  • 0

So I have several lists that are the headers of variables in a data file. The setup looks like this:

headerGroup1 = ["1", "2", "3, "4", "5"]
headerGroup2 = ["6", "7", "8, "9", "10"]
headerGroup3 = ["1", "2", "3", "4", "5"]

And I have a master file that looks like this:

masterVars = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]

I want to do three things:

  • Create a list that includes all the items from masterVars in order. And I don’t know if values are unique.
  • If a list item contained in headerGroupX is in the masterVars, prepend that header group to the list item.
  • Dump a list that contains all 64k items into something I can manage in SPSS (sort of kidding about this one)

I think this would be simple if there were only 2 lists. The big problem I think I’m running into is what happens after you prepend data to a list item. But I’m not totally sure what I’m messing up.

EDITED:

Here is an example of what I would want to output:

newMasterFile = ["headerGroup1, headerGroup3, 1", "headerGroup1, headerGroup3, 2", etc.]

Does this make anything clearer?

  • 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-14T03:36:25+00:00Added an answer on June 14, 2026 at 3:36 am
    import functools # python3 compatibility (for reduce function)
    
    # unsorted - see 3,4 are swaped!
    masterVars = ["1", "2", "4", "3", "5", "6", "7", "8", "9", "10"]
    
    input_dict=dict(headerGroup1 = ["1", "2", "3", "4", "5"],headerGroup2 = ["6", "7", "8", "9", "10"],headerGroup3 = ["1", "2", "3", "4", "5"])
    
    # used builtins sorted function for sorting 
    new_master_file=[' '.join(j[0])+' '+j[1] for j in [functools.reduce(lambda a,b:(i in input_dict[b] and a[0]+[b] or a[0],i),input_dict,[[],i]) for i in sorted(masterVars,key=int)]]
    
    for i in new_master_file:
        print (i)
    

    Or do you like more readable version? 😉

    PS. What is SPSS?

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

Sidebar

Related Questions

I have several unordered lists that I want to display like this: <ul> <li><img></li>
I have several lists that I would like to map together, but I can't
I have several lists in Matlab that I want to write to the same
I have a site that lists several upcoming events, and each event has a
I have an object model that contains several lists of other objects. I want
I have a gen_server speaking to several hardware sensors. This setup works fine. Now
I have several arrays of arrays or arrays of dicts that I would like
I have a WPF user control that contains a DataGrid. This DG contains several
I have several lists in a sitecollection that are currently using ListTemplateID 101 (DocumentLibary).
I have an object in a list that I need to rank several different

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.