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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:22:44+00:00 2026-05-26T10:22:44+00:00

In Maple 15, I have a nested list like this one (only 2 levels

  • 0

In Maple 15, I have a nested list like this one (only 2 levels of nesting):

[[a,b],[c],[d,e,f]]

I want to create 6 lists from that one (the number of elements..), like these:

[[x,a,b],[c],[d,e,f]]
[[a,x,b],[c],[d,e,f]]
[[a,b],[x,c],[d,e,f]]
[[a,b],[c],[x,d,e,f]]
[[a,b],[c],[d,x,e,f]]
[[a,b],[c],[d,e,x,f]]

I tried but I have super complex loops and it doesn’t work.. any more brilliant idea?

  • 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-26T10:22:44+00:00Added an answer on May 26, 2026 at 10:22 am

    I am writing this code on Maple 7, but it should work with pretty much any version of Maple. I feel that it is easier to do things by first stripping the original nested list into two simple lists:

    input:=[[a,b],[c],[d,e,f]];
    flatlist:=[seq(op(input[n]),n=1..nops(input))]; % flat list of all elements
    noels:=[seq(nops(input[n]),n=1..nops(input))]; % numbers of elements in sub-lists
    

    It is easier to insert your extra elements into the new flat lists:

    newlists:=[seq([seq(flatlist[i],i=1..n-1),x,seq(flatlist[i],i=n..nops(flatlist))],n=1..nops(flatlist))];
    newnoels:=[seq(seq([seq(noels[i],i=1..n-1),noels[n]+1,seq(noels[i],i=n+1..nops(noels))],m=1..noels[n]),n=1..nops(noels))];
    

    The resulting flat lists must be converted back into the nested lists. This can be done by writing a simple function:

    mergelists:=proc(flatlist,noels)
      local i,j,n,result;
      i:=0; result:=NULL;
      for n from 1 to nops(noels) do
        result:=result,[seq(flatlist[i+j],j=1..noels[n])];
        i:=i+noels[n];
      od;
      return [result];
    end:
    

    With this function available, it is now easy to convert the prepared data into the required format:

    output:=[seq(mergelists(newlists[n],newnoels[n]),n=1..nops(newlists))];
    

    I admit that this may not be the most elegant solution possible. Unfortunately, nothing simpler comes to my mind just now.

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

Sidebar

Related Questions

i have a xml file on a server that look for example like this
I have a field that has values like this... s:10:03/16/1983; s:4:Male; s:2:No; I'd like
I have a project that has several build configurations (FREE version, male-only, female-only, etc.).
I have a class like that: public class Customer { public string Name {get;
I have a list of divs on a page that all contain 3 divs
I have to write a program that read from a file that contains the
What I am trying to do is create ideally a nested List basically a
I have more than 1 app that are exaclty the same. The only difference
I have html where I only want to hide the text portion, but what
So I have an equation like this: I need to get G[xy] . How

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.