Eliminate empty elements from a list with a specific patternList operation on specific elementsSelect elements from list with given headSelecting elements from a list with nullsReplace empty list elements with patternReplacing Non-Constant Elements from List with Patternselecting elements from a list with two numbersRemoving elements of a specific length from a listEliminate types of elements from the listListPlot3D with empty matrix elementsDelete a large pattern from one list

How to answer pointed "are you quitting" questioning when I don't want them to suspect

How can I fix this gap between bookcases I made?

Is "plugging out" electronic devices an American expression?

What is the command to reset a PC without deleting any files

Mapping arrows in commutative diagrams

Is domain driven design an anti-SQL pattern?

What's the difference between repeating elections every few years and repeating a referendum after a few years?

How to move the player while also allowing forces to affect it

New order #4: World

How to make payment on the internet without leaving a money trail?

Patience, young "Padovan"

Latin words with no plurals in English

What to wear for invited talk in Canada

aging parents with no investments

Can a planet have a different gravitational pull depending on its location in orbit around its sun?

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

Why doesn't a const reference extend the life of a temporary object passed via a function?

What does "enim et" mean?

Denied boarding due to overcrowding, Sparpreis ticket. What are my rights?

I see my dog run

Doomsday-clock for my fantasy planet

Re-submission of rejected manuscript without informing co-authors

What is the meaning of "of trouble" in the following sentence?

Why airport relocation isn't done gradually?



Eliminate empty elements from a list with a specific pattern


List operation on specific elementsSelect elements from list with given headSelecting elements from a list with nullsReplace empty list elements with patternReplacing Non-Constant Elements from List with Patternselecting elements from a list with two numbersRemoving elements of a specific length from a listEliminate types of elements from the listListPlot3D with empty matrix elementsDelete a large pattern from one list













3












$begingroup$


I am really new in this patterns part of Mathematica. Basically what I need to do is eliminate null elements from a list but that has a specific name before the empty element. For example, my list is:



list="a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2"


and I need to obtain



list="a12-b11-1", "d33-c22-2"


The list was created using



list = Flatten[Table[ ToString[namea[[i]] <> "-" <> nameb[[j]] <> "-" <> 
ToString[ Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1] ]],
i, 1, 4, j, 1, 4], 1]


and for some values it writtes because there is not a value equal to $0.5$. Until now I have been able to do it term by term as



list//."a11-b11-"-> Sequence[]


but the real list contains a lot of elements and could be almost impossible to do it that way to solve the problem. I think my main problem is that I am not sure how to specify the pattern search (something like " *-name " in gnu/linux). Is there a wise way to do this?. Thanks in advance.










share|improve this question











$endgroup$











  • $begingroup$
    Have a look at DeleteCases and StringMatchQ or StringContainsQ.
    $endgroup$
    – b.gatessucks
    8 hours ago










  • $begingroup$
    I think it would be more efficient to first filter out the unwanted cases in the int function, and then construct strings only from the remaining ones.
    $endgroup$
    – Roman
    8 hours ago











  • $begingroup$
    @b.gatessucks Thank you, I will look those option in Mathematica.
    $endgroup$
    – mors
    8 hours ago










  • $begingroup$
    @Roman You are right, but I am new ih this cases stuf in Mathematica and I did no know how to do it when I created the list.
    $endgroup$
    – mors
    8 hours ago















3












$begingroup$


I am really new in this patterns part of Mathematica. Basically what I need to do is eliminate null elements from a list but that has a specific name before the empty element. For example, my list is:



list="a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2"


and I need to obtain



list="a12-b11-1", "d33-c22-2"


The list was created using



list = Flatten[Table[ ToString[namea[[i]] <> "-" <> nameb[[j]] <> "-" <> 
ToString[ Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1] ]],
i, 1, 4, j, 1, 4], 1]


and for some values it writtes because there is not a value equal to $0.5$. Until now I have been able to do it term by term as



list//."a11-b11-"-> Sequence[]


but the real list contains a lot of elements and could be almost impossible to do it that way to solve the problem. I think my main problem is that I am not sure how to specify the pattern search (something like " *-name " in gnu/linux). Is there a wise way to do this?. Thanks in advance.










share|improve this question











$endgroup$











  • $begingroup$
    Have a look at DeleteCases and StringMatchQ or StringContainsQ.
    $endgroup$
    – b.gatessucks
    8 hours ago










  • $begingroup$
    I think it would be more efficient to first filter out the unwanted cases in the int function, and then construct strings only from the remaining ones.
    $endgroup$
    – Roman
    8 hours ago











  • $begingroup$
    @b.gatessucks Thank you, I will look those option in Mathematica.
    $endgroup$
    – mors
    8 hours ago










  • $begingroup$
    @Roman You are right, but I am new ih this cases stuf in Mathematica and I did no know how to do it when I created the list.
    $endgroup$
    – mors
    8 hours ago













3












3








3


1



$begingroup$


I am really new in this patterns part of Mathematica. Basically what I need to do is eliminate null elements from a list but that has a specific name before the empty element. For example, my list is:



list="a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2"


and I need to obtain



list="a12-b11-1", "d33-c22-2"


The list was created using



list = Flatten[Table[ ToString[namea[[i]] <> "-" <> nameb[[j]] <> "-" <> 
ToString[ Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1] ]],
i, 1, 4, j, 1, 4], 1]


and for some values it writtes because there is not a value equal to $0.5$. Until now I have been able to do it term by term as



list//."a11-b11-"-> Sequence[]


but the real list contains a lot of elements and could be almost impossible to do it that way to solve the problem. I think my main problem is that I am not sure how to specify the pattern search (something like " *-name " in gnu/linux). Is there a wise way to do this?. Thanks in advance.










share|improve this question











$endgroup$




I am really new in this patterns part of Mathematica. Basically what I need to do is eliminate null elements from a list but that has a specific name before the empty element. For example, my list is:



list="a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2"


and I need to obtain



list="a12-b11-1", "d33-c22-2"


The list was created using



list = Flatten[Table[ ToString[namea[[i]] <> "-" <> nameb[[j]] <> "-" <> 
ToString[ Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1] ]],
i, 1, 4, j, 1, 4], 1]


and for some values it writtes because there is not a value equal to $0.5$. Until now I have been able to do it term by term as



list//."a11-b11-"-> Sequence[]


but the real list contains a lot of elements and could be almost impossible to do it that way to solve the problem. I think my main problem is that I am not sure how to specify the pattern search (something like " *-name " in gnu/linux). Is there a wise way to do this?. Thanks in advance.







list-manipulation filtering






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago









Roman

4,65511128




4,65511128










asked 8 hours ago









morsmors

496




496











  • $begingroup$
    Have a look at DeleteCases and StringMatchQ or StringContainsQ.
    $endgroup$
    – b.gatessucks
    8 hours ago










  • $begingroup$
    I think it would be more efficient to first filter out the unwanted cases in the int function, and then construct strings only from the remaining ones.
    $endgroup$
    – Roman
    8 hours ago











  • $begingroup$
    @b.gatessucks Thank you, I will look those option in Mathematica.
    $endgroup$
    – mors
    8 hours ago










  • $begingroup$
    @Roman You are right, but I am new ih this cases stuf in Mathematica and I did no know how to do it when I created the list.
    $endgroup$
    – mors
    8 hours ago
















  • $begingroup$
    Have a look at DeleteCases and StringMatchQ or StringContainsQ.
    $endgroup$
    – b.gatessucks
    8 hours ago










  • $begingroup$
    I think it would be more efficient to first filter out the unwanted cases in the int function, and then construct strings only from the remaining ones.
    $endgroup$
    – Roman
    8 hours ago











  • $begingroup$
    @b.gatessucks Thank you, I will look those option in Mathematica.
    $endgroup$
    – mors
    8 hours ago










  • $begingroup$
    @Roman You are right, but I am new ih this cases stuf in Mathematica and I did no know how to do it when I created the list.
    $endgroup$
    – mors
    8 hours ago















$begingroup$
Have a look at DeleteCases and StringMatchQ or StringContainsQ.
$endgroup$
– b.gatessucks
8 hours ago




$begingroup$
Have a look at DeleteCases and StringMatchQ or StringContainsQ.
$endgroup$
– b.gatessucks
8 hours ago












$begingroup$
I think it would be more efficient to first filter out the unwanted cases in the int function, and then construct strings only from the remaining ones.
$endgroup$
– Roman
8 hours ago





$begingroup$
I think it would be more efficient to first filter out the unwanted cases in the int function, and then construct strings only from the remaining ones.
$endgroup$
– Roman
8 hours ago













$begingroup$
@b.gatessucks Thank you, I will look those option in Mathematica.
$endgroup$
– mors
8 hours ago




$begingroup$
@b.gatessucks Thank you, I will look those option in Mathematica.
$endgroup$
– mors
8 hours ago












$begingroup$
@Roman You are right, but I am new ih this cases stuf in Mathematica and I did no know how to do it when I created the list.
$endgroup$
– mors
8 hours ago




$begingroup$
@Roman You are right, but I am new ih this cases stuf in Mathematica and I did no know how to do it when I created the list.
$endgroup$
– mors
8 hours ago










2 Answers
2






active

oldest

votes


















7












$begingroup$

If the list elements are strings, as it appears after your comment, you can use Select with a string pattern:



list = "a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2";
Select[list, Not@*StringMatchQ[__ ~~ ""]]



"a12-b11-1", "d33-c22-2"




You could also Select before making the strings:



L = DeleteCases[
Flatten[
Table[
namea[[i]], nameb[[j]], Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1],
i, 4, j, 4],
1],
_, _, ];


and then make these into strings:



StringRiffle[ToString /@ #, "-"] & /@ L


I can't check this because you didn't supply functioning code.






share|improve this answer











$endgroup$












  • $begingroup$
    Thank you, I forgot to specify the way the list is created. I create the list as 'list = Flatten[Table[ ToString[namea[[i]] <> "-" <> nameb[[j]] <> "-" <> ToString[ Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1] ]], i, 1, 4, j, 1, 4], 1] '
    $endgroup$
    – mors
    8 hours ago



















0












$begingroup$

In 10.1, two functions were added to handle a pair of very common cases: StringStartsQ and StringEndsQ which return True if the string matches a pattern at the beginning or end, respectively. So, while Roman's answer gives you the full general form, most of the pattern can be eliminated by using



list = "a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2";
Select[list, Not@*StringEndsQ[""]]


instead.






share|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    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/3.0/"u003ecc by-sa 3.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%2f194815%2feliminate-empty-elements-from-a-list-with-a-specific-pattern%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7












    $begingroup$

    If the list elements are strings, as it appears after your comment, you can use Select with a string pattern:



    list = "a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2";
    Select[list, Not@*StringMatchQ[__ ~~ ""]]



    "a12-b11-1", "d33-c22-2"




    You could also Select before making the strings:



    L = DeleteCases[
    Flatten[
    Table[
    namea[[i]], nameb[[j]], Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1],
    i, 4, j, 4],
    1],
    _, _, ];


    and then make these into strings:



    StringRiffle[ToString /@ #, "-"] & /@ L


    I can't check this because you didn't supply functioning code.






    share|improve this answer











    $endgroup$












    • $begingroup$
      Thank you, I forgot to specify the way the list is created. I create the list as 'list = Flatten[Table[ ToString[namea[[i]] <> "-" <> nameb[[j]] <> "-" <> ToString[ Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1] ]], i, 1, 4, j, 1, 4], 1] '
      $endgroup$
      – mors
      8 hours ago
















    7












    $begingroup$

    If the list elements are strings, as it appears after your comment, you can use Select with a string pattern:



    list = "a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2";
    Select[list, Not@*StringMatchQ[__ ~~ ""]]



    "a12-b11-1", "d33-c22-2"




    You could also Select before making the strings:



    L = DeleteCases[
    Flatten[
    Table[
    namea[[i]], nameb[[j]], Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1],
    i, 4, j, 4],
    1],
    _, _, ];


    and then make these into strings:



    StringRiffle[ToString /@ #, "-"] & /@ L


    I can't check this because you didn't supply functioning code.






    share|improve this answer











    $endgroup$












    • $begingroup$
      Thank you, I forgot to specify the way the list is created. I create the list as 'list = Flatten[Table[ ToString[namea[[i]] <> "-" <> nameb[[j]] <> "-" <> ToString[ Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1] ]], i, 1, 4, j, 1, 4], 1] '
      $endgroup$
      – mors
      8 hours ago














    7












    7








    7





    $begingroup$

    If the list elements are strings, as it appears after your comment, you can use Select with a string pattern:



    list = "a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2";
    Select[list, Not@*StringMatchQ[__ ~~ ""]]



    "a12-b11-1", "d33-c22-2"




    You could also Select before making the strings:



    L = DeleteCases[
    Flatten[
    Table[
    namea[[i]], nameb[[j]], Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1],
    i, 4, j, 4],
    1],
    _, _, ];


    and then make these into strings:



    StringRiffle[ToString /@ #, "-"] & /@ L


    I can't check this because you didn't supply functioning code.






    share|improve this answer











    $endgroup$



    If the list elements are strings, as it appears after your comment, you can use Select with a string pattern:



    list = "a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2";
    Select[list, Not@*StringMatchQ[__ ~~ ""]]



    "a12-b11-1", "d33-c22-2"




    You could also Select before making the strings:



    L = DeleteCases[
    Flatten[
    Table[
    namea[[i]], nameb[[j]], Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1],
    i, 4, j, 4],
    1],
    _, _, ];


    and then make these into strings:



    StringRiffle[ToString /@ #, "-"] & /@ L


    I can't check this because you didn't supply functioning code.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 4 hours ago

























    answered 8 hours ago









    RomanRoman

    4,65511128




    4,65511128











    • $begingroup$
      Thank you, I forgot to specify the way the list is created. I create the list as 'list = Flatten[Table[ ToString[namea[[i]] <> "-" <> nameb[[j]] <> "-" <> ToString[ Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1] ]], i, 1, 4, j, 1, 4], 1] '
      $endgroup$
      – mors
      8 hours ago

















    • $begingroup$
      Thank you, I forgot to specify the way the list is created. I create the list as 'list = Flatten[Table[ ToString[namea[[i]] <> "-" <> nameb[[j]] <> "-" <> ToString[ Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1] ]], i, 1, 4, j, 1, 4], 1] '
      $endgroup$
      – mors
      8 hours ago
















    $begingroup$
    Thank you, I forgot to specify the way the list is created. I create the list as 'list = Flatten[Table[ ToString[namea[[i]] <> "-" <> nameb[[j]] <> "-" <> ToString[ Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1] ]], i, 1, 4, j, 1, 4], 1] '
    $endgroup$
    – mors
    8 hours ago





    $begingroup$
    Thank you, I forgot to specify the way the list is created. I create the list as 'list = Flatten[Table[ ToString[namea[[i]] <> "-" <> nameb[[j]] <> "-" <> ToString[ Select[int[i, j, 0.5], Abs[#] == 0.5 &, 1] ]], i, 1, 4, j, 1, 4], 1] '
    $endgroup$
    – mors
    8 hours ago












    0












    $begingroup$

    In 10.1, two functions were added to handle a pair of very common cases: StringStartsQ and StringEndsQ which return True if the string matches a pattern at the beginning or end, respectively. So, while Roman's answer gives you the full general form, most of the pattern can be eliminated by using



    list = "a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2";
    Select[list, Not@*StringEndsQ[""]]


    instead.






    share|improve this answer









    $endgroup$

















      0












      $begingroup$

      In 10.1, two functions were added to handle a pair of very common cases: StringStartsQ and StringEndsQ which return True if the string matches a pattern at the beginning or end, respectively. So, while Roman's answer gives you the full general form, most of the pattern can be eliminated by using



      list = "a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2";
      Select[list, Not@*StringEndsQ[""]]


      instead.






      share|improve this answer









      $endgroup$















        0












        0








        0





        $begingroup$

        In 10.1, two functions were added to handle a pair of very common cases: StringStartsQ and StringEndsQ which return True if the string matches a pattern at the beginning or end, respectively. So, while Roman's answer gives you the full general form, most of the pattern can be eliminated by using



        list = "a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2";
        Select[list, Not@*StringEndsQ[""]]


        instead.






        share|improve this answer









        $endgroup$



        In 10.1, two functions were added to handle a pair of very common cases: StringStartsQ and StringEndsQ which return True if the string matches a pattern at the beginning or end, respectively. So, while Roman's answer gives you the full general form, most of the pattern can be eliminated by using



        list = "a11-b11-", "a12-b11-1", "c11-d22-", "d33-c22-2";
        Select[list, Not@*StringEndsQ[""]]


        instead.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        rcollyerrcollyer

        28.6k674166




        28.6k674166



























            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%2f194815%2feliminate-empty-elements-from-a-list-with-a-specific-pattern%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

            How to create a command for the “strange m” symbol in latex? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How do you make your own symbol when Detexify fails?Writing bold small caps with mathpazo packageplus-minus symbol with parenthesis around the minus signGreek character in Beamer document titleHow to create dashed right arrow over symbol?Currency symbol: Turkish LiraDouble prec as a single symbol?Plus Sign Too Big; How to Call adfbullet?Is there a TeX macro for three-legged pi?How do I get my integral-like symbol to align like the integral?How to selectively substitute a letter with another symbol representing the same letterHow do I generate a less than symbol and vertical bar that are the same height?

            Българска екзархия Съдържание История | Български екзарси | Вижте също | Външни препратки | Литература | Бележки | НавигацияУстав за управлението на българската екзархия. Цариград, 1870Слово на Ловешкия митрополит Иларион при откриването на Българския народен събор в Цариград на 23. II. 1870 г.Българската правда и гръцката кривда. От С. М. (= Софийски Мелетий). Цариград, 1872Предстоятели на Българската екзархияПодмененият ВеликденИнформационна агенция „Фокус“Димитър Ризов. Българите в техните исторически, етнографически и политически граници (Атлас съдържащ 40 карти). Berlin, Königliche Hoflithographie, Hof-Buch- und -Steindruckerei Wilhelm Greve, 1917Report of the International Commission to Inquire into the Causes and Conduct of the Balkan Wars

            Чепеларе Съдържание География | История | Население | Спортни и природни забележителности | Културни и исторически обекти | Религии | Обществени институции | Известни личности | Редовни събития | Галерия | Източници | Литература | Външни препратки | Навигация41°43′23.99″ с. ш. 24°41′09.99″ и. д. / 41.723333° с. ш. 24.686111° и. д.*ЧепелареЧепеларски Linux fest 2002Начало на Зимен сезон 2005/06Национални хайдушки празници „Капитан Петко Войвода“Град ЧепелареЧепеларе – народният ски курортbgrod.orgwww.terranatura.hit.bgСправка за населението на гр. Исперих, общ. Исперих, обл. РазградМузей на родопския карстМузей на спорта и скитеЧепеларебългарскибългарскианглийскитукИстория на градаСки писти в ЧепелареВремето в ЧепелареРадио и телевизия в ЧепелареЧепеларе мами с родопски чар и добри пистиЕвтин туризъм и снежни атракции в ЧепелареМестоположениеИнформация и снимки от музея на родопския карст3D панорами от ЧепелареЧепелареррр