Re: list question... unique values in all possible unique spots

2008-08-11 Thread ToshiBoy
Thank you for all your responses. I've tried the permutations road (thank you to all those of you who have suggested it) and it takes %*& %^ long :-) As expected. I've solved it a different way, which runs through the 26 spots by just adding one at a time if available. Still takes a long time, but

Re: list question... unique values in all possible unique spots

2008-08-11 Thread Mensanator
On Aug 11, 7:34 pm, [EMAIL PROTECTED] wrote: > Mensanator: > > > Ever tried to iterate 403 septillion times? > > The OP is talking about formulas, like: > X + Y * Z = W > Where X, Y, Z, W distinct and in [1, 26], so you have C(26, 4) > combinations that's way less than 26! > > >>> binomial(26, 4) >

Re: list question... unique values in all possible unique spots

2008-08-11 Thread bearophileHUGS
Mensanator: > Ever tried to iterate 403 septillion times? The OP is talking about formulas, like: X + Y * Z = W Where X, Y, Z, W distinct and in [1, 26], so you have C(26, 4) combinations that's way less than 26! >>> binomial(26, 4) 14950 So this can be solved with a xcombinations() generator.

Re: list question... unique values in all possible unique spots

2008-08-11 Thread Mensanator
On Aug 11, 3:53 pm, Tobiah <[EMAIL PROTECTED]> wrote: > On Mon, 11 Aug 2008 13:46:10 -0700, Tobiah wrote: > > On Sat, 09 Aug 2008 08:07:26 -0700, Mensanator wrote: > > >> 40329146112660563558400 > > > I think it's only 4 septillion. > > I meant to say 403. Whatever. Ever tried to iterate 403

Re: list question... unique values in all possible unique spots

2008-08-11 Thread Tobiah
On Mon, 11 Aug 2008 13:46:10 -0700, Tobiah wrote: > On Sat, 09 Aug 2008 08:07:26 -0700, Mensanator wrote: > >> 40329146112660563558400 > > I think it's only 4 septillion. I meant to say 403. ** Posted from http://www.teranews.com ** -- http://mail.python.org/mailman/listinfo/python-list

Re: list question... unique values in all possible unique spots

2008-08-11 Thread Tobiah
On Mon, 11 Aug 2008 13:46:10 -0700, Tobiah wrote: > On Sat, 09 Aug 2008 08:07:26 -0700, Mensanator wrote: > >> 40329146112660563558400 > > I think it's only 4 septillion. I meant 403. ** Posted from http://www.teranews.com ** -- http://mail.python.org/mailman/listinfo/python-list

Re: list question... unique values in all possible unique spots

2008-08-11 Thread Tobiah
On Sat, 09 Aug 2008 08:07:26 -0700, Mensanator wrote: > 40329146112660563558400 I think it's only 4 septillion. Perfectly manageable. ** Posted from http://www.teranews.com ** -- http://mail.python.org/mailman/listinfo/python-list

Re: list question... unique values in all possible unique spots

2008-08-09 Thread Mensanator
On Aug 9, 8:05�am, ToshiBoy <[EMAIL PROTECTED]> wrote: > I'm wondering how to do this the most elegant way: I found this quiz > in some magazine. I've already solved it on paper, but want to write a > python program to solve it. It comes down to being able to represent > range(1,27) through a numbe

Re: list question... unique values in all possible unique spots

2008-08-09 Thread George Sakkis
On Aug 9, 9:05 am, ToshiBoy <[EMAIL PROTECTED]> wrote: > I'm wondering how to do this the most elegant way: I found this quiz > in some magazine. I've already solved it on paper, but want to write a > python program to solve it. It comes down to being able to represent > range(1,27) through a numb

Re: List question

2008-03-23 Thread Steven D'Aprano
On Sun, 23 Mar 2008 15:55:43 -0700, John Machin wrote: > On Mar 24, 12:19 am, Dustan <[EMAIL PROTECTED]> wrote: >> On Mar 21, 3:57 pm, Paul Rubin wrote: >> >> > [EMAIL PROTECTED] writes: >> > >if 'one' and 'two' in f: >> > >alist.append(f) >> >> > Use: >>

Re: List question

2008-03-23 Thread John Machin
On Mar 24, 12:19 am, Dustan <[EMAIL PROTECTED]> wrote: > On Mar 21, 3:57 pm, Paul Rubin wrote: > > > [EMAIL PROTECTED] writes: > > >if 'one' and 'two' in f: > > >alist.append(f) > > > Use: > > if 'one' in f and 'two' in f: ... > > Personally, I would

Re: List question

2008-03-23 Thread Dustan
On Mar 21, 3:57 pm, Paul Rubin wrote: > [EMAIL PROTECTED] writes: > >if 'one' and 'two' in f: > >alist.append(f) > > Use: > if 'one' in f and 'two' in f: ... Personally, I would put parentheses around to be clearer: if ('one' in f) and ('two' in f

Re: List question

2008-03-22 Thread Mensanator
On Mar 22, 8:40�pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Sat, 22 Mar 2008 14:55:39 -0700 (PDT), Zentrader > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > > > is funny and not mean. �In the words of whoever it was in "Gone With > > The Wind", frankly I don't give a

Re: List question

2008-03-22 Thread Steven D'Aprano
On Sat, 22 Mar 2008 14:55:39 -0700, Zentrader wrote: >> No one meant to laugh at you. Your naivete was not obvious. FWIW, a >> sense of humor is a valuable possession in most Python-related >> conversations. > > Perhaps someone can explain how telling something like this to the OP, > who thinks

Re: List question

2008-03-22 Thread Steven D'Aprano
On Sat, 22 Mar 2008 16:16:03 -0700, bearophileHUGS wrote: > bearophile: >> A more computer-friendly (and Pythonic) syntax may be ('are' is a >> keyword): > > Sorry for causing confusion, I was just thinking aloud. English isn't my > first language, and sometimes I slip a bit. There is nothing w

Re: List question

2008-03-22 Thread bearophileHUGS
bearophile: > A more computer-friendly (and Pythonic) syntax may be ('are' is a keyword): Sorry for causing confusion, I was just thinking aloud. English isn't my first language, and sometimes I slip a bit. Replace that with: > A more computer-friendly (and Pythonic) syntax may be ('are' is meant

Re: List question

2008-03-22 Thread Michael Wieher
If you can't laugh at your own stupidity, being a programmer will lead directly to insanity. =) 2008/3/22, Zentrader <[EMAIL PROTECTED]>: > > > No one meant to laugh at you. Your naivete was not obvious. FWIW, a > > sense of humor is a valuable possession in most Python-related > > conversations

Re: List question

2008-03-22 Thread Zentrader
> No one meant to laugh at you. Your naivete was not obvious. FWIW, a > sense of humor is a valuable possession in most Python-related > conversations. Perhaps someone can explain how telling something like this to the OP, who thinks this statement will work if 'one' and 'two' in f: is funny and

Re: List question

2008-03-22 Thread Jeff Schwab
Zentrader wrote: > On Mar 22, 10:07 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >> On Mar 22, 4:38 pm, Zentrader <[EMAIL PROTECTED]> wrote: >> if ('one', 'two') are in f: ... >>> "are" gives me an error in Python 2.5 with a "from future import *" >>> statement included. What version and p

Re: List question

2008-03-22 Thread Zentrader
On Mar 22, 10:07 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > On Mar 22, 4:38 pm, Zentrader <[EMAIL PROTECTED]> wrote: > > > > if ('one', 'two') are in f: ... > > > "are" gives me an error in Python 2.5 with a "from future import *" > > statement included. What version and platform are you ru

Re: List question

2008-03-22 Thread Arnaud Delobelle
On Mar 22, 4:38 pm, Zentrader <[EMAIL PROTECTED]> wrote: > > if ('one', 'two') are in f: ... > > "are" gives me an error in Python 2.5 with a "from future import *" > statement included.  What version and platform are you running.  Also, > the docs don't mention it.http://docs.python.org/ref/keywor

Re: List question

2008-03-22 Thread Zentrader
> if ('one', 'two') are in f: ... "are" gives me an error in Python 2.5 with a "from future import *" statement included. What version and platform are you running. Also, the docs don't mention it. http://docs.python.org/ref/keywords.html -- http://mail.python.org/mailman/listinfo/python-list

Re: List question

2008-03-21 Thread bearophileHUGS
Ricky Zhou: > Look at the this line: > if 'one' and 'two' in f: Very cute, it's the first time I see a bug like this. I think it's not a common enough pattern to justify a language change, but a bit smarter computer language may be able to do that too ;-) (it's not easy to tell the two meaning

Re: List question

2008-03-21 Thread Paul Rubin
[EMAIL PROTECTED] writes: > if 'one' and 'two' in f: > alist.append(f) Use: if 'one' in f and 'two' in f: ... -- http://mail.python.org/mailman/listinfo/python-list

Re: List question

2008-03-21 Thread Ricky Zhou
On 2008-03-21 05:16:41 PM, [EMAIL PROTECTED] wrote: > alist = [] > blist = [ 'one','two','one and two','one and four','five','one two'] > for f in blist: > if 'one' and 'two' in f: > alist.append(f) > > for i in alist: > print i > > two > one and two > one two > > >

Re: List Question

2007-10-03 Thread Bjoern Schliessmann
Pablo Ziliani wrote: > > > I always use this full-featured, all-inclusive, rock-solid version > (see the try/except block): > > count = i = 0 > x = 1 > y = [1,2,3,4,5,1,2,3,4,1,2,1] > try: > while count < 3: > if y[i] == x: > count += 1 > i += 1 > except RuntimeE

Re: List Question

2007-10-03 Thread Paul Hankin
On Oct 2, 11:09 pm, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Oct 2, 4:20 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > > On Oct 2, 10:06 pm, brad <[EMAIL PROTECTED]> wrote: > > > > How is this expressed in Python? > > > > If x is in y more than three times: > > > print x > > > > y is a Pyth

Re: List Question

2007-10-02 Thread Bruno Desthuilliers
brad a écrit : > How is this expressed in Python? > > If x is in y more than three times: > print x > > y is a Python list. if y.count(x) > 3: print x -- http://mail.python.org/mailman/listinfo/python-list

Re: List Question

2007-10-02 Thread Paul McGuire
On Oct 2, 4:58 pm, Pablo Ziliani <[EMAIL PROTECTED]> wrote: > Paul Hankin wrote: > > On Oct 2, 10:06 pm, brad <[EMAIL PROTECTED]> wrote: > > >> How is this expressed in Python? > > >> If x is in y more than three times: > >> print x > > >> y is a Python list. > > > Simple and readable: > > if

Re: List Question

2007-10-02 Thread Paul McGuire
On Oct 2, 4:20 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > On Oct 2, 10:06 pm, brad <[EMAIL PROTECTED]> wrote: > > > How is this expressed in Python? > > > If x is in y more than three times: > > print x > > > y is a Python list. > > Simple and readable: > if len([a for a in y if x == a]) > 3

Re: List Question

2007-10-02 Thread Pablo Ziliani
Paul Hankin wrote: > On Oct 2, 10:06 pm, brad <[EMAIL PROTECTED]> wrote: > >> How is this expressed in Python? >> >> If x is in y more than three times: >> print x >> >> y is a Python list. >> > > Simple and readable: > if len([a for a in y if x == a]) > 3: > print x > > Or the sli

Re: List Question

2007-10-02 Thread Paul Hankin
On Oct 2, 10:20 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > On Oct 2, 10:06 pm, brad <[EMAIL PROTECTED]> wrote: > > > How is this expressed in Python? > > > If x is in y more than three times: > > print x > > > y is a Python list. > > Simple and readable: > if len([a for a in y if x == a]) >

Re: List Question

2007-10-02 Thread Paul Hankin
On Oct 2, 10:06 pm, brad <[EMAIL PROTECTED]> wrote: > How is this expressed in Python? > > If x is in y more than three times: > print x > > y is a Python list. Simple and readable: if len([a for a in y if x == a]) > 3: print x Or the slightly-too-flashy version: if sum(1 for a in y if x

Re: List Question

2007-10-02 Thread Michael Bentley
On Oct 2, 2007, at 2:06 PM, brad wrote: > How is this expressed in Python? > > If x is in y more than three times: > print x > > y is a Python list. # Try using help -- help(list) or help(list.count) for instance... if y.count(x) > 3: print x -- http://mail.python.org/mailman/listinf