Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <v45d4b$3s5s4$1@dont-email.me>
Deutsch   English   Français   Italiano  
<v45d4b$3s5s4$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna <HenHanna@devnull.tb>
Newsgroups: comp.lang.python
Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
Date: Sun, 9 Jun 2024 16:16:27 -0700
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <v45d4b$3s5s4$1@dont-email.me>
References: <v456ak$3pmpo$1@dont-email.me>
 <e149526e-91aa-4dfe-963e-d371ed3d280b@mrabarnett.plus.com>
 <mailman.105.1717973614.2909.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 10 Jun 2024 01:16:28 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="fdf3da398add0912fb8385f840f76bc6";
	logging-data="4069252"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/rxrjS4EozxXXlRTyjgXd3ssnzAPg5Nj8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:C57sn9iYu2vK803OpIeSmHRcEco=
In-Reply-To: <mailman.105.1717973614.2909.python-list@python.org>
Content-Language: en-US
Bytes: 2260

On 6/9/2024 3:50 PM, MRAB wrote:
> On 2024-06-09 22:20, HenHanna via Python-list wrote:
>>
>> Chunk, ChunkC -- nice simple way(s) to write these in Python?
>>
>>
>> (Chunk  '(a a   b    a a a   b b))
>>       ==> ((a a) (b)  (a a a) (b b))
>>
>>
>> (Chunk  '(a a a a   b   c c   a a   d   e e e e))
>>       ==> ((a a a a) (b) (c c) (a a) (d) (e e e e))
>>
>>
>> (Chunk  '(2 2   foo   bar bar   j j j   k   baz baz))
>>       ==> ((2 2) (foo) (bar bar) (j j j) (k) (baz baz))
>>
>> _________________
>>
>> (ChunkC  '(a a   b b b))
>>        ==> ((a 2)  (b 3))
>>
>> (ChunkC  '(a a   b      a a a   b b))
>>        ==> ((a 2)  (b 1)  (a 3)   (b 2))
> 
> You can make use of itertools.groupby.
> 


Thanks!   i'll try it.


Scheme (Gauche)

(use srfi-1)   ; span

(define (gp x)
   (if (null? x) '()
     (let-values (((F L) (span (cut equal? (car x) <>) x)))
       (cons F (gp L)))))

(print (gp   '(a    b b    a a a   b b b b)))
(print (gp   '(c c c   a   d d d d   a   e e e e e)))