问题描述
skipper
由于我是初学者并且自学成才,因此欢迎提出任何相当简单的建议。如果我在做任何可怕的事情,也请指出。谢谢
解决方法
我将使用list comprehension删除所有出现的0:
b=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,0]
#b is a list of primes with composite numbers turned into zero!
# Iterates through all the values and returns them unless they are 0
b = [x for x in b if not x == 0]
print(b)