Skip to main content

filtering - Discard Elements of list with given criteria


I have the following list:


{{3506, 0.120908, 
0.213813, <|1 -> {7, 9, 18, 20}, 6 -> {15}|>}, {3726, 0.119108,
0.209133, <|1 -> {6, 8, 9, 13, 18, 20}, 3 -> {15}|>}, {3761,
0.116293,
0.203036, <|1 -> {6, 8, 14, 18, 20}, 2 -> {12}, 4 -> {15}|>}, {3946,
0.107619,
0.192869, <|3 -> {6}, 1 -> {7, 18, 20}, 2 -> {12}|>}, {4016,

0.104384,
0.190066, <|1 -> {6, 7, 10, 15, 18, 20}, 6 -> {12}|>}, {4086,
0.106909,
0.187285, <|5 -> {11, 12}, 4 -> {15}, 1 -> {18, 20}|>}, {4236,
0.103937,
0.188204, <|1 -> {5, 6, 8, 14, 18, 20}, 5 -> {12}|>}, {4271,
0.103541,
0.186671, <|1 -> {4, 7, 11, 13, 18, 20}, 5 -> {12},
2 -> {15}|>}, {4421, 0.101325,
0.186022, <|2 -> {5, 7}, 1 -> {6, 13, 18, 20}|>}, {4491, 0.101609,

0.180121, <|1 -> {4, 6, 7, 15, 18, 20}, 6 -> {11}|>}, {4491,
0.100645, 0.184125, <|3 -> {7}, 7 -> {10}, 1 -> {18, 20}|>}, {4526,
0.0989646,
0.17942, <|1 -> {5, 6, 14, 18, 20}, 2 -> {10}, 7 -> {12}|>}, {4561,
0.0945528,
0.175016, <|1 -> {5, 18, 20}, 5 -> {11}, 8 -> {12}|>}, {4816,
0.0968629,
0.172952, <|1 -> {3, 10, 18, 20}, 5 -> {11}, 6 -> {12},
2 -> {14}|>}, {4816, 0.100074,
0.171889, <|1 -> {6, 18, 20}, 2 -> {10, 14}, 10 -> {11}|>}, {4851,

0.0956618, 0.167787, <|15 -> {11}, 1 -> {12, 14, 18, 20}|>}, {4966,
0.0933867,
0.173685, <|2 -> {3}, 1 -> {5, 7, 10, 18, 20}, 5 -> {12}|>}, {5001,
0.0929784,
0.171669, <|1 -> {3, 4, 5, 11, 14, 18, 20}, 7 -> {12}|>}, {5186,
0.0923044,
0.169445, <|2 -> {4, 5, 11, 12}, 1 -> {6, 18, 20}|>}, {5221,
0.0938267,
0.16939, <|3 -> {3}, 1 -> {6, 18, 20}, 2 -> {10},
5 -> {12}|>}, {5256, 0.0900446,

0.167957, <|3 -> {5}, 5 -> {10, 12}, 1 -> {18, 20}|>}, {5256,
0.0953461,
0.167948, <|2 -> {4}, 1 -> {5, 13, 14, 15, 18, 20},
7 -> {11}|>}, {5291, 0.0919092,
0.164553, <|2 -> {5, 10}, 10 -> {11}, 1 -> {13, 18, 20}|>}, {5441,
0.0917546,
0.167778, <|1 -> {2, 7, 18, 20}, 3 -> {3, 12}, 2 -> {11}|>}, {5511,
0.091757,
0.165217, <|1 -> {4, 5, 7, 11, 18, 20}, 10 -> {10}|>}, {5511,
0.0931502,

0.163884, <|3 -> {4, 13}, 8 -> {11}, 1 -> {18, 20}|>}, {5581,
0.0952444,
0.163607, <|1 -> {2, 12, 18, 20}, 6 -> {10}, 7 -> {11},
3 -> {13}|>}, {5661, 0.0895339,
0.165808, <|1 -> {3, 10, 13, 15, 18, 20}, 5 -> {5}|>}, {5696,
0.0878405,
0.162595, <|4 -> {3}, 1 -> {4, 11, 18, 20}, 5 -> {12}|>}, {5731,
0.0884125,
0.162495, <|1 -> {2, 3, 18, 20}, 2 -> {5, 11}, 4 -> {10},
3 -> {12}|>}, {5766, 0.0904722,

0.161405, <|1 -> {2, 13, 18, 20}, 2 -> {4, 12}, 5 -> {10},
4 -> {11}|>}, {5766, 0.0921969,
0.161218, <|1 -> {3, 4, 6, 11, 18, 20}, 11 -> {10}|>}, {5881,
0.0843905,
0.161821, <|2 -> {3}, 5 -> {5}, 1 -> {12, 18, 20}|>}, {5916,
0.0864502,
0.160761, <|1 -> {3, 10, 13, 18, 20}, 2 -> {4, 11},
3 -> {5}|>}, {5951, 0.0879725,
0.160539, <|4 -> {3}, 1 -> {5, 13, 18, 20}, 3 -> {10, 12}|>}, {5986,
0.0892943,

0.159927, <|2 -> {3, 5}, 9 -> {10}, 1 -> {15, 18, 20}|>}, {6021,
0.0897165,
0.158098, <|1 -> {2, 14, 18, 20}, 2 -> {4}, 8 -> {10},
4 -> {11}|>}, {6126, 0.0921288,
0.156535, <|20 -> {10}, 2 -> {13}, 1 -> {18, 20}|>}, {6136,
0.0837377, 0.157748, <|6 -> {4}, 1 -> {5, 10, 11, 18, 20}|>}, {6206,
0.0858319,
0.157381, <|1 -> {2, 5, 12, 18, 20}, 3 -> {4}, 7 -> {10}|>}, {6206,
0.0867804,
0.157329, <|2 -> {2, 3}, 1 -> {5, 12, 18, 20}, 3 -> {10},

4 -> {11}|>}, {6206, 0.0872168,
0.157297, <|4 -> {3}, 1 -> {5, 12, 14, 18, 20}, 6 -> {10}|>}, {6241,
0.0862107,
0.155018, <|2 -> {3, 4, 11}, 9 -> {10}, 1 -> {18, 20}|>}, {6646,
0.085206,
0.154682, <|2 -> {2}, 3 -> {3, 10},
1 -> {4, 5, 14, 18, 20}|>}, {6751, 0.0862941,
0.152039, <|3 -> {2}, 1 -> {3, 11, 18, 20}, 12 -> {10}|>}}

I would like to discard the rows who's fourth element's sum of the key numbers times the length of the respective value vector is less than 4 and more than 12.



Sorry for the format of the list, but I can't find a way to code-format it.



Answer



Just an alternative:


Select[
list,
4 <= Tr @ KeyValueMap[# Length[#2] &, #[[-1]] ] <= 12 &
]

Comments

Popular posts from this blog

plotting - How to draw lines between specified dots on ListPlot?

I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...

dynamic - How can I make a clickable ArrayPlot that returns input?

I would like to create a dynamic ArrayPlot so that the rectangles, when clicked, provide the input. Can I use ArrayPlot for this? Or is there something else I should have to use? Answer ArrayPlot is much more than just a simple array like Grid : it represents a ranged 2D dataset, and its visualization can be finetuned by options like DataReversed and DataRange . These features make it quite complicated to reproduce the same layout and order with Grid . Here I offer AnnotatedArrayPlot which comes in handy when your dataset is more than just a flat 2D array. The dynamic interface allows highlighting individual cells and possibly interacting with them. AnnotatedArrayPlot works the same way as ArrayPlot and accepts the same options plus Enabled , HighlightCoordinates , HighlightStyle and HighlightElementFunction . data = {{Missing["HasSomeMoreData"], GrayLevel[ 1], {RGBColor[0, 1, 1], RGBColor[0, 0, 1], GrayLevel[1]}, RGBColor[0, 1, 0]}, {GrayLevel[0], GrayLevel...

list manipulation - Selecting multiple columns from a matrix?

Sample data: data = { {{2013, 1, 1}, 24.13, 167.67, 231.82}, {{2013, 1, 2}, 32.15, 170.92, 225.99}, {{2013, 1, 3}, 35.43, 172.68, 221.67}, {{2013, 1, 4}, 36.73, 173.05, 218.32}, {{2013, 1, 5}, 58.19, 165.96, 197.05}, {{2013, 1, 6}, 69.99, 163.50, 187.52}, {{2013, 1, 7}, 71.37, 154.21, 175.58}, {{2013, 1, 8}, 72.51, 149.66, 163.25}}; I want a DateListPlot with three graphs, so for a matrix formed by columns 1 and 2, one for columns 1 and 3, and 1 for columns 1 and 4. At the moment I'm using this code: data2 = Transpose[{data[[All, 1]], data[[All, 2]]}]; data3 = Transpose[{data[[All, 1]], data[[All, 3]]}]; data4 = Transpose[{data[[All, 1]], data[[All, 4]]}]; DateListPlot[{data2, data3, data4}, Joined -> True, Filling -> {3 -> {1}}] but I have a hunch that this can be done more efficiently. I don't like the Transpose s in particular. Any ideas? edit (for extra credit) What if I need to multiply the second column by 2, which in my solution is simp...