Find Prime numbers using list,primenumbers,#First build
文章由Byrx.net分享于2019-03-23 06:03:31
Find Prime numbers using list,primenumbers,#First build
#First build a list of non-prime numbers, using a single list comprehension, #then use another list comprehension to get the 'inverse' of the list, #which are prime numbers.noprimes = [j for i in range(2, 8) for j in range(i*2, 50, i)]primes = [x for x in range(2, 50) if x not in noprimes]print primes
相关内容
- List count(x),listcount,# Return the
- Introducing List Filtering,,li = ['a', '
- List for iteration,listforiteration,for x in [1,
- For Statements,forstatements,a = ['cat',
- To iterate over the indices of a sequence, combine range() and len(),
- Sort and reverse elements in list,reverseelements,scores = ['1
- List slice assignment: delete and insert,sliceassignment,L = ['spam
- List slicing,listslicing,numbers = [1
- A tuple consists of a number of values separated by commas,tuplecom
- tuple assignment,tuple,nudge = 1win
评论关闭