Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个清单:
list1 = range(0,11)
我现在想删除可被某个其他数字整除的所有数字n。有没有一种简单的方法来实现这一点?
n
只需使用列表推导 -
list1 = [i for i in list1 if not(i%3==0)]
关于列表推导的一些参考