haishi 发表于 2017-4-29 12:49:38

一行循环搞定,python的魅力

  if __name__ == '__main__':
  keys = ("distribution.ftp.type1","distribution.ftp.type2","distribution.ftp.type3")
  types = set( for k in keys if k.startswith('distribution.ftp.')])
  print types
  执行,输出结果如下
  set(['type1', 'type3', 'type2'])
  你懂得
  红色部分如此简单,同样功能如果换做其他编程语言,绝非一行能够搞定,所以这就是python的魅力:简单
页: [1]
查看完整版本: 一行循环搞定,python的魅力