考虑我有一个元素数组,其中我想创建一个新的'iterable',每个下一个应用一个自定义'转换'。在python 2.x下做这件事的正确方法是什么?如何将一个函数应用于一组元素
对于熟悉Java的人来说,相当于来自谷歌集合框架的Iterables#转换。
确定作为一个虚设例如
Iterable<Foo> foos = Iterables.transform(strings, new Function<String, Foo>()
{
public Foo apply(String string) {
return new Foo(string);
}
});
//use foos below
一些具体的例子会很有用。 –