memo:リスト内包表記
pythonは}なり、endなりでブロック?が閉じていかないので
気持ち悪いったらありゃしない。
タイプ量が減るようによく考えられてるなぁと思う。
#filter map reduce #pythonは構文きれい、とはいうものの割とキモいですね。 #無名関数はjavascriptの構文が読みやすいのですね。 def fx(x) : return x % 2 !=0 and x % 3 != 0 for x in filter(fx,range(2,100)): print x,"\t", print for x in map(lambda x:x * 3,range(1,10)): print x,"\t", print print reduce(lambda x,y:x + y,range(1,10)) #リスト内包表記はpythonの本領発揮ゾーンなんだろうなぁ #filter/map/lambdaより簡潔です!とはいうもののパッと見わけわからない。 freshfruit = [' banana',' loganberry','passion fruit '] print [weapon.strip() for weapon in freshfruit] #for文と中身が逆に書かれてるのですか vec = [2,4,6] #リスト内包的map print [3*x for x in vec] #リスト内包的map&filter print [3*x for x in vec if x > 3] # map処理 数える filter処理 って書くのね #二次元配列にマップ print [[x,x**2] for x in vec]