Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-27 Thread Steven Bethard
I wrote: Kent Johnson wrote: You can do the same thing using a PYTHONSTARTUP file - see http://docs.python.org/tut/node4.html#SECTION00424 You can change the prompts with import sys sys.ps1 = ' >>> ' sys.ps2 = ' ... ' Very cool. I didn't know about this. Does anyone know how to

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-20 Thread Scott David Daniels
Bengt Richter wrote: Not true on NT4 at least: Alt-Spacebar gets you the system menu paste into the dos window with Alt-spacebar e p Thanks immensely for this -- I love it. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-17 Thread Bengt Richter
On Fri, 17 Dec 2004 08:03:12 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: >Steven Bethard wrote: >> Very cool. I didn't know about this. Does anyone know how to make it >> work with Pythonwin[1]? (Obviously, I can type the above in manually >> every time, but I'd much rather have Pythonwin

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-17 Thread Fernando Perez
Keith Dart wrote: > Fernando Perez wrote: > >> >> >> You might want to look at ipython: >> >> http://ipython.scipy.org, >> >> >> >> > > I did just recently install that. It looks very nice. Would make a great > interactive prompt for an IDE, as well. Glad you like it :) And yes, there are

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-17 Thread Steven Bethard
Kent Johnson wrote: You can copy and paste from a Windows command prompt. It's a bit bizarre, but - In the system menu for a command window, pick Properties - On the Options tab, turn on Quick Edit mode - Now you can copy and paste with right-click (!). If you have text selected, right-click will

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-17 Thread Kent Johnson
Steven Bethard wrote: Very cool. I didn't know about this. Does anyone know how to make it work with Pythonwin[1]? (Obviously, I can type the above in manually every time, but I'd much rather have Pythonwin do this automatically for me.) Steve [1] I'd do my example code at the command prompt

Re: do you master list comprehensions?

2004-12-17 Thread aleks90210
Thought you might enjoy my super-small flatten function: (though google groups seems to be munging my whitespace today) def flatten(d): "flatten([[[1,[2,3],[4,5]],6],[7]])==[1,2,3,4,5,6,7]" return reduce(lambda a,b:a+b,[(type(x) in (list, tuple) \ and flatten(x) or [x]) for x in d]) -- http://ma

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Keith Dart
Fernando Perez wrote: You might want to look at ipython: http://ipython.scipy.org, I did just recently install that. It looks very nice. Would make a great interactive prompt for an IDE, as well. -- \/ \/ (O O) -- oOOo~(

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Fernando Perez
Kent Johnson wrote: > Keith Dart wrote: >> What I do is set Python's sys.ps1 variable to something else. I have a >> module called "interactive" that I import implicitly by shell alias: >> >> py='python -i -c '\''import interactive'\' >> >> Which, among other things, sets the prompt to "Python>

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Steven Bethard
Kent Johnson wrote: You can do the same thing using a PYTHONSTARTUP file - see http://docs.python.org/tut/node4.html#SECTION00424 You can change the prompts with import sys sys.ps1 = ' >>> ' sys.ps2 = ' ... ' Very cool. I didn't know about this. Does anyone know how to make it

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Kent Johnson
Keith Dart wrote: What I do is set Python's sys.ps1 variable to something else. I have a module called "interactive" that I import implicitly by shell alias: py='python -i -c '\''import interactive'\' Which, among other things, sets the prompt to "Python> " You can do the same thing using a PYTHO

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Roel Schroeven
Steve Holden wrote: Nick Coghlan wrote: $ python Python 2.4 (#1, Dec 4 2004, 20:10:33) [GCC 3.3.3 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.ps1 = ".>>> "; sys.ps2 = " " .>>> print """\ It isn't that hard"""

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Keith Dart
Steve Holden wrote: Nick Coghlan wrote: Roel Schroeven wrote: Stefan Behnel wrote: This is the first time I see that and I totally like the idea of writing ".>>>" instead of ">>>" at the beginning of a line. Thank you Dr. Dobb! It's unfortunate for c.l.py that Python uses ">>>" as the default pr

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Steve Holden
Nick Coghlan wrote: Roel Schroeven wrote: Stefan Behnel wrote: This is the first time I see that and I totally like the idea of writing ".>>>" instead of ">>>" at the beginning of a line. Thank you Dr. Dobb! It's unfortunate for c.l.py that Python uses ">>>" as the default prompt as it messes up

Re: do you master list comprehensions?

2004-12-16 Thread Nick Coghlan
Nick Coghlan wrote: (FYI, I filed bug report #1085744 on SF about this) And Raymond Hettinger was able to decipher my somewhat incoherent rambling (tip: don't try to write bug reports in the wee hours of the morning) and produce a potentially useful modification to PySequence_Tuple. Anyway, I gu

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Nick Coghlan
Roel Schroeven wrote: Stefan Behnel wrote: This is the first time I see that and I totally like the idea of writing ".>>>" instead of ">>>" at the beginning of a line. Thank you Dr. Dobb! It's unfortunate for c.l.py that Python uses ">>>" as the default prompt as it messes up the display on mail

Re: ".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Roel Schroeven
Stefan Behnel wrote: Nick Coghlan schrieb: data = [['foo','bar','baz'],['my','your'],['holy','grail']] result = [] for d in data: .>>> data = [['foo','bar','baz'],['my','your'],['holy','grail']] .>>> from itertools import chain .>>> result = "".join(chain(*data)) 'foobarbazmyyourholygrail' This i

".>>>" is a good idea! (OT, was: Re: do you master list comprehensions?)

2004-12-16 Thread Stefan Behnel
Nick Coghlan schrieb: data = [['foo','bar','baz'],['my','your'],['holy','grail']] result = [] for d in data: .>>> data = [['foo','bar','baz'],['my','your'],['holy','grail']] .>>> from itertools import chain .>>> result = "".join(chain(*data)) 'foobarbazmyyourholygrail' This is the first time I see

Re: do you master list comprehensions?

2004-12-15 Thread Fredrik Lundh
Matthew Moss wrote: >> >>> data = [['foo','bar','baz'],['my','your'],['holy','grail']] >> >>> [e for l in data for e in l] >> ['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail'] > > Okay, I tried this in an interactive Python session and it works as > stated. My question is, why? How is the inte

Re: do you master list comprehensions?

2004-12-15 Thread Matthew Moss
Diez B. Roggisch wrote: > >>> data = [['foo','bar','baz'],['my','your'],['holy','grail']] > >>> [e for l in data for e in l] > ['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail'] Okay, I tried this in an interactive Python session and it works as stated. My question is, why? How is the interpre

Re: do you master list comprehensions?

2004-12-15 Thread Nick Coghlan
Will Stuyvesant wrote: Here is a question about list comprehensions [lc]. The question is dumb because I can do without [lc]; but I am posing the question because I am curious. This: data = [['foo','bar','baz'],['my','your'],['holy','grail']] result = [] for d in data: ... for w in d: ...

Re: do you master list comprehensions?

2004-12-14 Thread Steven Bethard
Timothy Babytch wrote: Will Stuyvesant wrote: data = [['foo','bar','baz'],['my','your'],['holy','grail']] sum(data, []) ['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail'] The second parameter passed to sum is just to overrride default initial value "zero". It's worth keeping in mind that this so

Re: do you master list comprehensions?

2004-12-14 Thread Fredrik Lundh
Steven Bethard wrote: > > python -m timeit -s "data = [range(10) for _ in range(1000)]" > "sum(data, [])" > 10 loops, best of 3: 54.2 msec per loop > > > python -m timeit -s "data = [range(10) for _ in range(1000)]" "[w for > d in data for w in d]" > 100 loops, best of 3: 1.75 msec per loop > > Th

Re: do you master list comprehensions?

2004-12-14 Thread Timothy Babytch
Will Stuyvesant wrote: data = [['foo','bar','baz'],['my','your'],['holy','grail']] sum(data, []) ['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail'] The second parameter passed to sum is just to overrride default initial value "zero". -- Timothy Babytch -- http://mail.python.org/mailman/listinfo/p

Re: do you master list comprehensions?

2004-12-14 Thread Jeremy Bowers
On Tue, 14 Dec 2004 00:41:36 +0100, Max M wrote: > Fredrik Lundh wrote: >> Max M wrote: >> >> I tried funnies like [[w for w in L] for L in data], >>> >>>That is absolutely correct. It's not a funnie at all. >> >> well, syntactically correct or not, it doesn't do what he want... > > Doh! *

Re: do you master list comprehensions?

2004-12-13 Thread Will Stuyvesant
Okay that was fun. Enlightening as I hoped. unroll() in Python, for arbitrary depth, _flatten in Tkinter (what else is in Tkinter!), sum() abuse. The sum(data,[]) was funniest, it works like ((['foo','bar'] + []) + ['my','your']) + ['holy','grail']. Before I think of such things I have already

Re: do you master list comprehensions?

2004-12-13 Thread Fredrik Lundh
Max M wrote: >> I tried funnies like [[w for w in L] for L in data], >> that is correct syntax, but you'd never guess. > > That is absolutely correct. It's not a funnie at all. If you find it odd it's > only because you are > not used to list comprehensiones. well, syntactically correct or not,

Re: do you master list comprehensions?

2004-12-13 Thread Max M
Fredrik Lundh wrote: Max M wrote: I tried funnies like [[w for w in L] for L in data], That is absolutely correct. It's not a funnie at all. well, syntactically correct or not, it doesn't do what he want... Doh! *I* might not be used to list comprehensions then... You are right. That example could

Re: do you master list comprehensions?

2004-12-13 Thread Max M
Will Stuyvesant wrote: I tried funnies like [[w for w in L] for L in data], that is correct syntax, but you'd never guess. That is absolutely correct. It's not a funnie at all. If you find it odd it's only because you are not used to list comprehensiones. In that case you might be more comfortabl

Re: do you master list comprehensions?

2004-12-13 Thread Peter Otten
Will Stuyvesant wrote: data = [['foo','bar','baz'],['my','your'],['holy','grail']] result = [] for d in data: > ... for w in d: > ...result.append(w) print result > ['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail'] > > puts all the words in a list, like I want.

do you master list comprehensions?

2004-12-13 Thread Will Stuyvesant
Here is a question about list comprehensions [lc]. The question is dumb because I can do without [lc]; but I am posing the question because I am curious. This: >>> data = [['foo','bar','baz'],['my','your'],['holy','grail']] >>> result = [] >>> for d in data: ... for w in d: ...result

Re: do you master list comprehensions?

2004-12-13 Thread Diez B. Roggisch
>>> data = [['foo','bar','baz'],['my','your'],['holy','grail']] >>> [e for l in data for e in l] ['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail'] -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list

Re: do you master list comprehensions?

2004-12-13 Thread Steven Bethard
Will Stuyvesant wrote: data = [['foo','bar','baz'],['my','your'],['holy','grail']] result = [] for d in data: ... for w in d: ...result.append(w) print result ['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail'] Take advantage of the fact that you can have more than one 'for' in a list

Re: do you master list comprehensions?

2004-12-13 Thread Luis M. Gonzalez
I guess the simplest to do it is like this: >>> data = [['foo','bar','baz'],['my','your'],['holy','grail']] >>> result=[w for d in data for w in d] >>> result ['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail'] >>> -- http://mail.python.org/mailman/listinfo/python-list

Re: do you master list comprehensions?

2004-12-13 Thread Fredrik Lundh
James Stroud wrote: > Here is one for arbitrary depth: > > def unroll(ary): > unrolled = [] > for item in ary: ># add test for your favorite sequence type >if ( type(item) == types.ListType or \ > type(item) == types.TupleType \ > ): > unrolled.extend(unroll(item

Re: do you master list comprehensions?

2004-12-13 Thread James Stroud
Here is one for arbitrary depth: def unroll(ary): unrolled = [] for item in ary: # add test for your favorite sequence type if ( type(item) == types.ListType or \ type(item) == types.TupleType \ ): unrolled.extend(unroll(item)) else: unrolled.appen

Re: do you master list comprehensions?

2004-12-13 Thread Luis M. Gonzalez
I guess the simplest way to do it is like this: >>> data = [['foo','bar','baz'],['my','your'],['holy','grail']] >>> result=[w for d in data for w in d] >>> result ['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail'] >>> -- http://mail.python.org/mailman/listinfo/python-list