Re: Slicing iterables in sub-generators without loosing elements

2012-10-02 Thread Ramchandra Apte
On Tuesday, 2 October 2012 22:13:20 UTC+5:30, Mark Lawrence wrote: > On 02/10/2012 17:12, Ramchandra Apte wrote: > > > On Monday, 1 October 2012 13:47:50 UTC+5:30, Mark Lawrence wrote: > > >> On 01/10/2012 01:58, 8 Dihedral wrote: > > >> > > >>> > > >> > > >>> Your question seems vague

Re: Slicing iterables in sub-generators without loosing elements

2012-10-02 Thread 88888 Dihedral
Steven D'Aprano於 2012年10月3日星期三UTC+8上午9時24分13秒寫道: > On Tue, 02 Oct 2012 18:11:20 -0700, 8 Dihedral wrote: > > > > > Steven D'Aprano於 2012年10月3日星期三UTC+8上午8時57分20秒寫道: > > > > >> Oh, I'm convinced that it's a bot. > > >> The fact that Dihedral never responds to conversations about him/it is

Re: Slicing iterables in sub-generators without loosing elements

2012-10-02 Thread Steven D'Aprano
On Tue, 02 Oct 2012 18:11:20 -0700, 8 Dihedral wrote: > Steven D'Aprano於 2012年10月3日星期三UTC+8上午8時57分20秒寫道: >> Oh, I'm convinced that it's a bot. >> The fact that Dihedral never responds to conversations about him/it is >> a give away: nearly all people are far to egotistical to let >> accusatio

Re: Slicing iterables in sub-generators without loosing elements

2012-10-02 Thread 88888 Dihedral
Steven D'Aprano於 2012年10月3日星期三UTC+8上午8時57分20秒寫道: > On Wed, 03 Oct 2012 03:58:02 +1000, Chris Angelico wrote: > > > > > Dihedral might be a bot and might not. I've come to the conclusion that > > > it's not worth trying to find out, given that a good bot can outdo a lot > > > of humans in usefu

Re: Slicing iterables in sub-generators without loosing elements

2012-10-02 Thread 88888 Dihedral
On Monday, October 1, 2012 4:17:50 PM UTC+8, Mark Lawrence wrote: > On 01/10/2012 01:58, 8 Dihedral wrote: > > > > > > Your question seems vague to me. If you know you are storing > > > only immutable tuples in a list, then the way to iterate is simple. > > > > > > > Does Python have a m

Re: Slicing iterables in sub-generators without loosing elements

2012-10-02 Thread Terry Reedy
On 10/2/2012 1:58 PM, Chris Angelico wrote: On Wed, Oct 3, 2012 at 2:44 AM, Mark Lawrence wrote: What happened to freedom of speech? If I want to talk to a bot, I'll talk to a bot. Besides I'm not convinced it/he/she is a bot. Plus if you read my post carefully, add in several years experien

Re: Slicing iterables in sub-generators without loosing elements

2012-10-02 Thread Mark Lawrence
On 02/10/2012 18:58, Chris Angelico wrote: Dihedral might be a bot and might not. I've come to the conclusion that it's not worth trying to find out, given that a good bot can outdo a lot of humans in useful conversation. ChrisA Try telling that to the newbies on the Python tutor mailing lis

Re: Slicing iterables in sub-generators without loosing elements

2012-10-02 Thread Chris Angelico
On Wed, Oct 3, 2012 at 2:44 AM, Mark Lawrence wrote: > What happened to freedom of speech? If I want to talk to a bot, I'll talk > to a bot. Besides I'm not convinced it/he/she is a bot. Plus if you read > my post carefully, add in several years experience of Python the language > and Python th

Re: Slicing iterables in sub-generators without loosing elements

2012-10-02 Thread Mark Lawrence
On 02/10/2012 17:12, Ramchandra Apte wrote: On Monday, 1 October 2012 13:47:50 UTC+5:30, Mark Lawrence wrote: On 01/10/2012 01:58, 8 Dihedral wrote: Your question seems vague to me. If you know you are storing only immutable tuples in a list, then the way to iterate is simple.

Re: Slicing iterables in sub-generators without loosing elements

2012-10-02 Thread Ramchandra Apte
On Monday, 1 October 2012 13:47:50 UTC+5:30, Mark Lawrence wrote: > On 01/10/2012 01:58, 8 Dihedral wrote: > > > > > > Your question seems vague to me. If you know you are storing > > > only immutable tuples in a list, then the way to iterate is simple. > > > > > > > Does Python have a

Re: Slicing iterables in sub-generators without loosing elements

2012-10-01 Thread Joshua Landau
On 1 October 2012 09:19, Mark Lawrence wrote: > On 01/10/2012 01:58, 8 Dihedral wrote: > >> >> Your question seems vague to me. If you know you are storing >> only immutable tuples in a list, then the way to iterate is simple. >> >> > Does Python have a magic method that let's me use mutable

Re: Slicing iterables in sub-generators without loosing elements

2012-10-01 Thread Mark Lawrence
On 01/10/2012 01:58, 8 Dihedral wrote: Your question seems vague to me. If you know you are storing only immutable tuples in a list, then the way to iterate is simple. Does Python have a magic method that let's me use mutable tuples? I'd also like immutable lists. Is it worth raising a

Re: Slicing iterables in sub-generators without loosing elements

2012-09-30 Thread 88888 Dihedral
On Sunday, September 30, 2012 12:15:57 AM UTC+8, Thomas Bach wrote: > Hi, > > > > say we have the following: > > > > >>> data = [('foo', 1), ('foo', 2), ('bar', 3), ('bar', 2)] > > > > is there a way to code a function iter_in_blocks such that > > > > >>> result = [ list(block) for bloc

Re: Slicing iterables in sub-generators without loosing elements

2012-09-29 Thread Thomas Bach
On Sat, Sep 29, 2012 at 09:26:00AM -0700, Paul Rubin wrote: > Thomas Bach writes: > > itertools.groupby(data, lambda (x,y) : x) > > is basically what you want. True! Thanks, Thomas Bach -- http://mail.python.org/mailman/listinfo/python-list

Re: Slicing iterables in sub-generators without loosing elements

2012-09-29 Thread Ian Kelly
On Sat, Sep 29, 2012 at 10:14 AM, Thomas Bach wrote: > Hi, > > say we have the following: > data = [('foo', 1), ('foo', 2), ('bar', 3), ('bar', 2)] > > is there a way to code a function iter_in_blocks such that > result = [ list(block) for block in iter_in_blocks(data) ] > > evaluates to

Re: Slicing iterables in sub-generators without loosing elements

2012-09-29 Thread Paul Rubin
Thomas Bach writes: result = [ [('foo', 1), ('foo', 2)], [('bar', 3), ('bar', 2)] ] > by _only_ _iterating_ over the list (caching all the elements sharing > the same first element doesn't count)? itertools.groupby(data, lambda (x,y) : x) is basically what you want. -- http://mail.python.o