Python Onliner: Filter Prime Numbers


Python Onliner Filter Prime Numbers

Here are some one-liners from Linghao:一行 Python 能实现什么丧心病狂的功能?

  • Find out prime numbers using filter(lambda x: all(map(lambda p: x % p != 0, range(2, x))), range(2, n))
  • Read csv file: with open('t.csv', 'r') as f: rows = [line.strip().split(',') for line in f.readlines()]
  • Transpose a matrix m = [ [1,2],[3,4]] zip(*m)

Published: by ;

Lei Ma (2015). 'Python Onliner: Filter Prime Numbers', Datumorphism, 12 April. Available at:

Table of Contents

Current Ref:

  • til/programming/