在Groovy中,什么时候使用Expando与'as'运算符和闭包有什么意义呢?(In Groovy, When Does It Makes Sense To Use An Expando vs the 'as' operator and Closures?)
Groovy是一种很棒的语言,提供了许多不同的选择。
在考虑单元测试时,使用Expando对象与使用闭包的“as”运算符何时有意义?
http://groovy.codehaus.org/Developer+Testing+using+Maps+and+Expandos+instead+of+Mocks vs http://groovy.codehaus.org/Developer+Testing+using+Closures+instead+of+嘲弄
对于简单的情况,它们的使用似乎非常相似。
谢谢!
Groovy is a wonderful language that offers lots of different choices.
In thinking about unit tests, when does it make sense to use an Expando object vs. the "as" operator with closures?
http://groovy.codehaus.org/Developer+Testing+using+Maps+and+Expandos+instead+of+Mocks vs http://groovy.codehaus.org/Developer+Testing+using+Closures+instead+of+Mocks
For simple cases, their use seems so similar.
Thanks!
原文:https://stackoverflow.com/questions/4709317
最满意答案
与@ Chitoge的解决方案几乎相同,
但为了匹配您的预期输出,这是我的解决方案
d={'foo': 10,'bar': 12,'asd': 4} key_list = [] key_index = [] for k,v in d.iteritems(): if v<=10: key_list.append(k) key_index.append(d.keys().index(k) + 1) print key_list print key_index
almost same as @Chitoge's solution,
but in order to match your expected output, here is my solution
d={'foo': 10,'bar': 12,'asd': 4} key_list = [] key_index = [] for k,v in d.iteritems(): if v<=10: key_list.append(k) key_index.append(d.keys().index(k) + 1) print key_list print key_index
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
如果tr具有div或span作为后代,可以使用.has()进行检查: $('table tr').has('div,span').addClass('someClass'); 检查下面的代码片段: $('table tr').has('div,span').addClass('someClass'); .someClass { background-color: red; }