Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
for (auto it = m.begin(); it != m.end();) {
if (!p(it->second)) {
it = m.erase(it);
} else {
++it;
}
}
real, dimension(:), allocatable :: a
a = pack(a,p(a))
!
elemental logical function p(x)
real, intent(in) :: x
p = x > 0.7
end function p
for k, v := range m {
if !p(v) {
delete(m, k)
}
}
m.entrySet().removeIf(e -> !p.test(e));
$p = sub { $_[0] };
while ( ($k,$v) = each %m ) {
$f{$k} = $v if $p->($v);
}
%m = %f;
$p = sub { $_[0] };
foreach $k (keys %m) {
delete $m{$k} if not $p->( $m{$k} );
}
m = {k:v for k, v in m.items() if p(v)}
for k in list(m):
if p(m[k]): m.pop(k)
m = dict(filter(p, m.items()))
m.select{|k,v| p(v) }
m.retain(|_, &mut v| p(v));