LINQ in IronPython

Viewed 626

I have a question about usage method in IronPython. Let's say I have some collection and then I create IronPython anonymous type from that collection and I want to iterate all over that collection. My code looks like this:

listInt = List[int]([0, 1, 2, 3, 4])
firstCollection = listInt.Select(lambda(v): type('SomeType', (object,),{"TypeValue": v*v, "TypeIndex": v})())
enumeratorFirst = IEnumerable[object].GetEnumerator(firstCollection)
while enumeratorFirst.MoveNext():
    item = enumeratorFirst.Current

This code works fine. But when I use Select method with index incorporating, then I get error: 'int' object is not iterable. Error

My code looks like this:

listInt = List[int]([0, 1, 2, 3, 4])
secondCollection = listInt.Select(lambda(v, i): type('SomeType', (object,), {"TypeValue": v*v, "TypeIndex": i})())
enumeratorSecond = IEnumerable[object].GetEnumerator(secondCollection)
while enumeratorSecond.MoveNext():
    item = enumeratorSecond.Current

Can anyone provide me with some help? Why there is error in second case?

P.S.: For interface usage I looked here: Interface In IronPython. For anonymous type usage I looked here: Anonymous objects in Python.

1 Answers
Related