其他
有趣的超短Python代码
让列表的每个元素都乘以2
求列表中所有元素之和
判断一个字符串中是否存在某些词
tweet = "This is an example tweet talking about scala an sbt"
print (list(map(lambda x:x in tweet.split(),wordlist)))
Python split()通过指定分隔符对字符串进行切片,这里默认为空格
读取txt文件
for line in open("D:\\test.txt"):print(line)祝你生日快乐
print (list(map(lambda x: "happy birthday to "+("YOU" if x!=2 else "dear Name"),range(4))))本文代码由陈鸥辉老师修改,参考代码:
作者:榴莲Xtt
参考链接:https://blog.csdn.net/windows_2015/article/details/51893405?utm_source=blogxgwz2