Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional selection of nested lists in Mathematica

Considering :

list= {{{{21, 22}, 283}, {{26, 13}, 28}, {{32, 17}, 531}, {{31, 11}, 
187}, {{30, 9}, 154}, {{25, 12}, 377}, {{12, 16}, 
285}}, {{{20, 19}, 183}, {{11, 23}, 249}, {{18, 21}, 
174}, {{12, 21}, 513}, {{24, 23}, 233}, {{29, 20}, 
465}}, {{{18, 20}, 136}, {{13, 23}, 244}, {{19, 21}, 
228}, {{14, 16}, 453}, {{14, 22}, 201}, {{18, 22}, 
417}, {{10, 22}, 217}, {{17, 23}, 180}}, {{{22, 20}, 
123}, {{25, 17}, 210}, {{28, 10}, 536}, {{27, 13}, 
296}, {{19, 11}, 391}, {{23, 18}, 305}, {{24, 18}, 204}}}


Length /@ list

{7, 6, 8, 7}

Question is :

How could I select the sublist with a length > 7 for example. I have been trying a lot of Position / Select unsuccessfully :-(

like image 959
500 Avatar asked Jun 03 '26 00:06

500


1 Answers

Select[list, Length@# > 7 &]  

Edit

When in doubt, you can test how the criteria is evaluating its argument. For example:

Select[{a, b, c}, Print]

Or a little bit more on the classical path:

Reap@Select[{a, b, c}, Sow]

Thanks to Brett for his suggestion in the comments below

like image 51
Dr. belisarius Avatar answered Jun 05 '26 13:06

Dr. belisarius