extracting sublistsSplitting a list by specifying section headersList Manipulation questionList rearrangement...

Is the mass of paint relevant in rocket design?

Can an integer optimization problem be convex?

Is this Portent-like spell balanced?

On the meaning of 'anyways' in "What Exactly Is a Quartz Crystal, Anyways?"

Strange Sticky Substance on Digital Camera

What do you do if you have developments on your paper during the long peer review process?

Is it really necessary to have a four hour meeting in Sprint planning?

Does wetting a beer glass change the foam characteristics?

Performance for simple code that converts a RGB tuple to hex string

Cut a cake into 3 equal portions with only a knife

Safely hang a mirror that does not have hooks

Is it a good idea to leave minor world details to the reader's imagination?

Examples of "unsuccessful" theories with afterlives

How to manage expenditure when billing cycles and paycheck cycles are not aligned?

What is the meaning of "heutig" in this sentence?

Conflict with hidden names

How do I set a custom order for folders on Windows 7 and 10?

2000s Animated TV show where teenagers could physically go into a virtual world

How to justify a team increase when the team is doing good?

How do I deal with too many NPCs in my campaign?

What is the difference between an astronaut in the ISS and a freediver in perfect neutral buoyancy?

How to say "cheat sheet" in French

Why does NASA publish all the results/data it gets?

Could Apollo astronauts see city lights from the moon?



extracting sublists


Splitting a list by specifying section headersList Manipulation questionList rearrangement by rulesprepending to elements of a listGeneration of sublists from a listdelete elements from list by ruleDeleting certain integers from string listExtracting sublists that contain similar elements






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3












$begingroup$


I have a list consisting of DateObjects and strings:



lis = {DateObject[{2019, 1, 1}], "a", "b", DateObject[{2019, 1, 2}], "c", "d", "e", DateObject[{2019, 1, 3}], "f"};


I would like to construct a function that takes as its argument a DateObject, and have it return all the following string elements that follow it in lis until the next occurrence of a DateObject in the list.



If the argument is DateObject[{2019,1,2}], then the return would be:



res = {"c","d","e"}


There probably are many ways to do this. I tried using SplitBy[lis, DateObjectQ] then SequenceCases but no luck.










share|improve this question











$endgroup$





















    3












    $begingroup$


    I have a list consisting of DateObjects and strings:



    lis = {DateObject[{2019, 1, 1}], "a", "b", DateObject[{2019, 1, 2}], "c", "d", "e", DateObject[{2019, 1, 3}], "f"};


    I would like to construct a function that takes as its argument a DateObject, and have it return all the following string elements that follow it in lis until the next occurrence of a DateObject in the list.



    If the argument is DateObject[{2019,1,2}], then the return would be:



    res = {"c","d","e"}


    There probably are many ways to do this. I tried using SplitBy[lis, DateObjectQ] then SequenceCases but no luck.










    share|improve this question











    $endgroup$

















      3












      3








      3





      $begingroup$


      I have a list consisting of DateObjects and strings:



      lis = {DateObject[{2019, 1, 1}], "a", "b", DateObject[{2019, 1, 2}], "c", "d", "e", DateObject[{2019, 1, 3}], "f"};


      I would like to construct a function that takes as its argument a DateObject, and have it return all the following string elements that follow it in lis until the next occurrence of a DateObject in the list.



      If the argument is DateObject[{2019,1,2}], then the return would be:



      res = {"c","d","e"}


      There probably are many ways to do this. I tried using SplitBy[lis, DateObjectQ] then SequenceCases but no luck.










      share|improve this question











      $endgroup$




      I have a list consisting of DateObjects and strings:



      lis = {DateObject[{2019, 1, 1}], "a", "b", DateObject[{2019, 1, 2}], "c", "d", "e", DateObject[{2019, 1, 3}], "f"};


      I would like to construct a function that takes as its argument a DateObject, and have it return all the following string elements that follow it in lis until the next occurrence of a DateObject in the list.



      If the argument is DateObject[{2019,1,2}], then the return would be:



      res = {"c","d","e"}


      There probably are many ways to do this. I tried using SplitBy[lis, DateObjectQ] then SequenceCases but no luck.







      list-manipulation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 8 hours ago









      C. E.

      55.5k3 gold badges108 silver badges220 bronze badges




      55.5k3 gold badges108 silver badges220 bronze badges










      asked 8 hours ago









      Suite401Suite401

      1,2644 silver badges12 bronze badges




      1,2644 silver badges12 bronze badges

























          4 Answers
          4






          active

          oldest

          votes


















          3














          $begingroup$

          SequenceCases[lis, {DateObject[{2019, 1, 2}], a:Except[_DateObject] ..., _DateObject} :> a]



          {"c", "d", "e"}




          Also



          Cases[lis,
          {___, DateObject[{2019, 1, 2}], a : Except[_DateObject] ..., _DateObject, ___} :> a, All]



          {"c", "d", "e"}







          share|improve this answer











          $endgroup$























            1














            $begingroup$

            f[data_List, d_DateObject] := Append[data, d -> {}]
            f[{dates___, d_ -> l_List}, s_String] := {dates, d -> Append[l, s]}
            lookup = Fold[f, {}, lis]


            Mathematica graphics



            We can now use this lookup like this:



            Mathematica graphics




            {"c", "d", "e"}







            share|improve this answer









            $endgroup$























              1














              $begingroup$

              lis = {
              DateObject[{2019, 1, 1}], "a", "b",
              DateObject[{2019, 1, 2}], "c", "d", "e",
              DateObject[{2019, 1, 3}], "f"};

              f[x_] := Rest[FirstCase[Split[lis, Head[#2] =!= DateObject &], {x, ___}]]

              res = f[DateObject[{2019, 1, 2}]]



              {"c", "d", "e"}







              share|improve this answer











              $endgroup$























                1














                $begingroup$

                Straight forward solution:



                dateExtract[date_DateObject, lis_List] :=
                FirstPosition[lis, date] //
                Drop[lis, First@#] & //
                TakeWhile[#, Not@*DateObjectQ] &





                share|improve this answer









                $endgroup$


















                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "387"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });















                  draft saved

                  draft discarded
















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206562%2fextracting-sublists%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  3














                  $begingroup$

                  SequenceCases[lis, {DateObject[{2019, 1, 2}], a:Except[_DateObject] ..., _DateObject} :> a]



                  {"c", "d", "e"}




                  Also



                  Cases[lis,
                  {___, DateObject[{2019, 1, 2}], a : Except[_DateObject] ..., _DateObject, ___} :> a, All]



                  {"c", "d", "e"}







                  share|improve this answer











                  $endgroup$




















                    3














                    $begingroup$

                    SequenceCases[lis, {DateObject[{2019, 1, 2}], a:Except[_DateObject] ..., _DateObject} :> a]



                    {"c", "d", "e"}




                    Also



                    Cases[lis,
                    {___, DateObject[{2019, 1, 2}], a : Except[_DateObject] ..., _DateObject, ___} :> a, All]



                    {"c", "d", "e"}







                    share|improve this answer











                    $endgroup$


















                      3














                      3










                      3







                      $begingroup$

                      SequenceCases[lis, {DateObject[{2019, 1, 2}], a:Except[_DateObject] ..., _DateObject} :> a]



                      {"c", "d", "e"}




                      Also



                      Cases[lis,
                      {___, DateObject[{2019, 1, 2}], a : Except[_DateObject] ..., _DateObject, ___} :> a, All]



                      {"c", "d", "e"}







                      share|improve this answer











                      $endgroup$



                      SequenceCases[lis, {DateObject[{2019, 1, 2}], a:Except[_DateObject] ..., _DateObject} :> a]



                      {"c", "d", "e"}




                      Also



                      Cases[lis,
                      {___, DateObject[{2019, 1, 2}], a : Except[_DateObject] ..., _DateObject, ___} :> a, All]



                      {"c", "d", "e"}








                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 7 hours ago

























                      answered 8 hours ago









                      kglrkglr

                      218k10 gold badges248 silver badges499 bronze badges




                      218k10 gold badges248 silver badges499 bronze badges




























                          1














                          $begingroup$

                          f[data_List, d_DateObject] := Append[data, d -> {}]
                          f[{dates___, d_ -> l_List}, s_String] := {dates, d -> Append[l, s]}
                          lookup = Fold[f, {}, lis]


                          Mathematica graphics



                          We can now use this lookup like this:



                          Mathematica graphics




                          {"c", "d", "e"}







                          share|improve this answer









                          $endgroup$




















                            1














                            $begingroup$

                            f[data_List, d_DateObject] := Append[data, d -> {}]
                            f[{dates___, d_ -> l_List}, s_String] := {dates, d -> Append[l, s]}
                            lookup = Fold[f, {}, lis]


                            Mathematica graphics



                            We can now use this lookup like this:



                            Mathematica graphics




                            {"c", "d", "e"}







                            share|improve this answer









                            $endgroup$


















                              1














                              1










                              1







                              $begingroup$

                              f[data_List, d_DateObject] := Append[data, d -> {}]
                              f[{dates___, d_ -> l_List}, s_String] := {dates, d -> Append[l, s]}
                              lookup = Fold[f, {}, lis]


                              Mathematica graphics



                              We can now use this lookup like this:



                              Mathematica graphics




                              {"c", "d", "e"}







                              share|improve this answer









                              $endgroup$



                              f[data_List, d_DateObject] := Append[data, d -> {}]
                              f[{dates___, d_ -> l_List}, s_String] := {dates, d -> Append[l, s]}
                              lookup = Fold[f, {}, lis]


                              Mathematica graphics



                              We can now use this lookup like this:



                              Mathematica graphics




                              {"c", "d", "e"}








                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 8 hours ago









                              C. E.C. E.

                              55.5k3 gold badges108 silver badges220 bronze badges




                              55.5k3 gold badges108 silver badges220 bronze badges


























                                  1














                                  $begingroup$

                                  lis = {
                                  DateObject[{2019, 1, 1}], "a", "b",
                                  DateObject[{2019, 1, 2}], "c", "d", "e",
                                  DateObject[{2019, 1, 3}], "f"};

                                  f[x_] := Rest[FirstCase[Split[lis, Head[#2] =!= DateObject &], {x, ___}]]

                                  res = f[DateObject[{2019, 1, 2}]]



                                  {"c", "d", "e"}







                                  share|improve this answer











                                  $endgroup$




















                                    1














                                    $begingroup$

                                    lis = {
                                    DateObject[{2019, 1, 1}], "a", "b",
                                    DateObject[{2019, 1, 2}], "c", "d", "e",
                                    DateObject[{2019, 1, 3}], "f"};

                                    f[x_] := Rest[FirstCase[Split[lis, Head[#2] =!= DateObject &], {x, ___}]]

                                    res = f[DateObject[{2019, 1, 2}]]



                                    {"c", "d", "e"}







                                    share|improve this answer











                                    $endgroup$


















                                      1














                                      1










                                      1







                                      $begingroup$

                                      lis = {
                                      DateObject[{2019, 1, 1}], "a", "b",
                                      DateObject[{2019, 1, 2}], "c", "d", "e",
                                      DateObject[{2019, 1, 3}], "f"};

                                      f[x_] := Rest[FirstCase[Split[lis, Head[#2] =!= DateObject &], {x, ___}]]

                                      res = f[DateObject[{2019, 1, 2}]]



                                      {"c", "d", "e"}







                                      share|improve this answer











                                      $endgroup$



                                      lis = {
                                      DateObject[{2019, 1, 1}], "a", "b",
                                      DateObject[{2019, 1, 2}], "c", "d", "e",
                                      DateObject[{2019, 1, 3}], "f"};

                                      f[x_] := Rest[FirstCase[Split[lis, Head[#2] =!= DateObject &], {x, ___}]]

                                      res = f[DateObject[{2019, 1, 2}]]



                                      {"c", "d", "e"}








                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited 7 hours ago

























                                      answered 7 hours ago









                                      Chris DegnenChris Degnen

                                      22.7k2 gold badges38 silver badges89 bronze badges




                                      22.7k2 gold badges38 silver badges89 bronze badges


























                                          1














                                          $begingroup$

                                          Straight forward solution:



                                          dateExtract[date_DateObject, lis_List] :=
                                          FirstPosition[lis, date] //
                                          Drop[lis, First@#] & //
                                          TakeWhile[#, Not@*DateObjectQ] &





                                          share|improve this answer









                                          $endgroup$




















                                            1














                                            $begingroup$

                                            Straight forward solution:



                                            dateExtract[date_DateObject, lis_List] :=
                                            FirstPosition[lis, date] //
                                            Drop[lis, First@#] & //
                                            TakeWhile[#, Not@*DateObjectQ] &





                                            share|improve this answer









                                            $endgroup$


















                                              1














                                              1










                                              1







                                              $begingroup$

                                              Straight forward solution:



                                              dateExtract[date_DateObject, lis_List] :=
                                              FirstPosition[lis, date] //
                                              Drop[lis, First@#] & //
                                              TakeWhile[#, Not@*DateObjectQ] &





                                              share|improve this answer









                                              $endgroup$



                                              Straight forward solution:



                                              dateExtract[date_DateObject, lis_List] :=
                                              FirstPosition[lis, date] //
                                              Drop[lis, First@#] & //
                                              TakeWhile[#, Not@*DateObjectQ] &






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered 6 hours ago









                                              sakrasakra

                                              3,39314 silver badges30 bronze badges




                                              3,39314 silver badges30 bronze badges


































                                                  draft saved

                                                  draft discarded



















































                                                  Thanks for contributing an answer to Mathematica Stack Exchange!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  Use MathJax to format equations. MathJax reference.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206562%2fextracting-sublists%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                                                  Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                                                  Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...