Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8378 > unrolled thread
| Started by | "Colin J. Williams" <cjw@ncf.ca> |
|---|---|
| First post | 2011-06-24 10:09 -0400 |
| Last post | 2011-06-24 16:29 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: reg: playing with the list "Colin J. Williams" <cjw@ncf.ca> - 2011-06-24 10:09 -0400
Re: reg: playing with the list Laurent Claessens <moky.math@gmail.com> - 2011-06-24 16:29 +0200
| From | "Colin J. Williams" <cjw@ncf.ca> |
|---|---|
| Date | 2011-06-24 10:09 -0400 |
| Subject | Re: reg: playing with the list |
| Message-ID | <mailman.369.1308924616.1164.python-list@python.org> |
On 24-Jun-11 03:01 AM, kaustubh joshi wrote: > Hey all, > I am new here and new to python too. In general new to programming . > I was working on aproblem. > and need some help. > I have a list of numbers say [2,3,5,6,10,15] > which all divide number 30. > Now i have to reduce this list to the numbers which are prime in number. > i.e. > [2,3,5] > can somebody suggest? > K > You might try writing the boolean function is_prime(n) for almost any n. There was a recent discussion on this topic. Colin W.
[toc] | [next] | [standalone]
| From | Laurent Claessens <moky.math@gmail.com> |
|---|---|
| Date | 2011-06-24 16:29 +0200 |
| Message-ID | <iu270k$5cr$1@news.univ-fcomte.fr> |
| In reply to | #8378 |
> You might try writing the boolean function is_prime(n) for almost any n.
>
> There was a recent discussion on this topic.
Since the guy is "new in programming", I complete the answer, just in
case. Using the function is_prime(n),
FIRST POSSIBILITY :
new_list=[]
for n in old_list:
if is_prime(n):
new_list.append(n)
SECOND POSSIBILITY :
new_list=[ n for n in old_list if is_prime(n) ]
There is a primiality test in Sage which is basically a module over
python (www.sagemath.org).
Have a good WE
Laurent
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web