如何从tcl列表中删除emty元素 [英] how to remove emty elements from tcl list

查看:350
本文介绍了如何从tcl列表中删除emty元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我有以下列表

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

我想删除所有为空的元素.因为列表列表是我无法在单循环交互中完成的.

有什么简单的方法可以实现这一目标吗?

解决方案

该列表中没有空元素.看起来空的可以视为(a)字符串"{}"或(b)包含一个元素的列表,该元素是空字符串或空列表.

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

hi I have following list

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

I want to remove all the elements which are empty. since list of list is i am not able to do it in single loop interation.

Any simple way to achieve this?

解决方案

There are no empty elements in that list. The ones that seem empty can be considered as (a) a 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}}}} \
              ]

这篇关于如何从tcl列表中删除emty元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆