print map(lambda x: x*2,range(1,11))
print sum(range(1,100)) #range(1,100)代表从1到100(不包含100)
wordlist = [“scala”,”akka”,”play framework”,”sbt”,”typesafe”]
tweet = “This is an example tweet talking about scala an sbt”
print map(lambda x:x in tweet.split(),wordlist)
print open(“test.txt”).readlines()
print map(lambda x: “happy birthday to” +(“YOU” if x!=2 else “dear Name”),range(4))
print reduce(lambda(a,b),c:(a+[c],b)if c >60 else (a,b+[c]),[49,58,76,82,88,90],([],[]))
结果:
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
4950
[True, False, False, True, False]
[‘this is a test\n’, ‘no more words’]
[‘happy birthday toYOU’, ‘happy birthday toYOU’, ‘happy birthday todear Name’, ‘happy birthday toYOU’]
([76, 82, 88, 90], [49, 58])