Seasons.NET

ちょっとした技術ブログです

List<>を使う

IronPythonでListを使う場合、stringと書いてはいけない。
strと統合されているらしく、"List[str]()"
と書く必要があります。
"[]"でくくるのがあんまりなじめないですが。。。

 1 import sys
 2 import clr
 3 from System.Collections.Generic import *
 4 
 5 items = ["ruby","perl","python"]
 6 lists = List[str]()
 7 
 8 # Add Item & Show
 9 for item in items:
10     lists.Add( item )
11     print item
12 
13 # Show List Item Count
14 print lists.Count