Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove empty string in list in Julia

I am looking for efficient solution to remove empty string in a list in Julia.

Here is my list :

li = ["one", "two", "three", " ", "four", "five"]

I can remove empty string by using for loop, as following :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

new_li = []
for i in li
    if i == " "
    else
        push!(new_li, i)
    end
end

But I believe there is more efficient way to remove the empty string.

>Solution :

new_li = filter((i) -> i != " ", l)

or

new_li = [i for i in l if i != " "]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading