具有长度值的Mathematica拆分列表

reu*_*gad 3 wolfram-mathematica

在Wolfram Mathematica 8.0中,我有一个嵌套列表,如:

             {{1,1,1},{0,0},{1,1,1,1,1},{0},{1,1},{0}}
Run Code Online (Sandbox Code Playgroud)

并且想要用子串长度替换那些,如下所示:

             {{3,3,3},{0,0},{5,5,5,5,5},{0},{2,2},{0}}
Run Code Online (Sandbox Code Playgroud)

任何人都能告诉我这个问题的快速功能方法吗?

Dan*_*lau 7

list = {{1, 1, 1}, {0, 0}, {1, 1, 1, 1, 1}, {0}, {1, 1}, {0}};
Map[Length[#]*# &, list]

Out[193]= {{3, 3, 3}, {0, 0}, {5, 5, 5, 5, 5}, {0}, {2, 2}, {0}}
Run Code Online (Sandbox Code Playgroud)