How to remove emty elements from tcl list

hi I have the following list

% set qprList {{{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{ }} {{}} {{}} 12345 {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{} } {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} { {}} {{}} {{}} 12345 {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{ }} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} 12345 {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} { {}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{} } {{}} {{}} {{}} 12345 {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}} {{}}}

I want to delete all empty elements. because the list of the list I can not do this in a single-threaded introduction.

Any easy way to achieve this?

+3
source share
4 answers

There are no empty items in this list. What appears to be empty can be thought of as (a) the string "{}" or (b) a list with one element, which is an empty string or an empty list.

package require struct::list
set non_empty [struct::list filter \
                 [struct::list flatten $qprList] \
                 {apply {{x} {expr {[string length $x] > 0}}}} \
              ]
+3
source

You can also try the following:

set listwithoutnulls [lsearch -all -inline -not -exact $listwithnulls {}]

Not included in the package. It can also be reapplied.

+2
source

From the Tckers Wiki ( http://wiki.tcl.tk/440 ):

Smooth list:

concat {*}$nested

It can be used several times:

proc flatten data { concat {*}$data }

set a {{a {b c}} {d {e f}}} ; # {a {b c}} {d {e f}} flatten $a ; # a {b c} d {e f} flatten [flatten $a] ; # a b c d e f

+1
source

I also use struct :: list because I'm lazy:

package require struct::list
set non_empty [struct::list flatten -full $qprList]
0
source

All Articles