Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Time to be aggressive. Go after a tattooed Virgo.


comp / comp.lang.python / RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

SubjectAuthor
* in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))HenHanna
+* Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))MRAB
|`- Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))HenHanna
+- RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))<avi.e.gross
+* RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))<avi.e.gross
|`* Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))HenHanna
| +- RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))<avi.e.gross
| `- Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))B. Pym
+* Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))Rob Cliffe
|`- Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))HenHanna
`- RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))<avi.e.gross

1
Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
From: HenHanna
Newsgroups: comp.lang.python, comp.lang.misc
Organization: A noiseless patient Spider
Date: Sun, 9 Jun 2024 21:20 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.python,comp.lang.misc
Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
Date: Sun, 9 Jun 2024 14:20:20 -0700
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <v456ak$3pmpo$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 09 Jun 2024 23:20:20 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ed01cd9e6d841d23fe19143a8bec1fed";
logging-data="3988280"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+031JokDcfFo3e+03SY6D5anWe9o6AndI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:OIh6iIs8scLZDA5oVR17jGMnAtI=
Content-Language: en-US
View all headers

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))

Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
From: MRAB
Newsgroups: comp.lang.python
Date: Sun, 9 Jun 2024 22:50 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: python@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
Date: Sun, 9 Jun 2024 23:50:26 +0100
Lines: 26
Message-ID: <mailman.105.1717973614.2909.python-list@python.org>
References: <v456ak$3pmpo$1@dont-email.me>
<e149526e-91aa-4dfe-963e-d371ed3d280b@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de gm2x5jnUJzg6Ebp+JyG8BQGPk2DGxZKYhhB9RHXXNZzw==
Cancel-Lock: sha1:08boEsHkoUaCQeH37m0iTDjkLjE= sha256:9F7kPOQKy2IuhfZ90+t69B0cDoQc9E/HQIXSOHVvqFc=
Return-Path: <python@mrabarnett.plus.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=plus.com header.i=@plus.com header.b=Gxh05UE4;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python?': 0.03;
'from:addr:python': 0.09; 'received:192.168.1.64': 0.09;
'subject:Python': 0.12; '(b)': 0.16; '(bar': 0.16;
'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16;
'message-id:@mrabarnett.plus.com': 0.16; 'received:plus.net':
0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.20; 'skip:_ 10':
0.22; 'header:User-Agent:1': 0.30; 'python-list': 0.32;
'received:192.168.1': 0.32; 'header:In-Reply-To:1': 0.34; 'bar':
0.35; 'received:192.168': 0.37; 'use': 0.39; 'received:212': 0.62;
'==>': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1717973427; bh=5usnBycXd9GRnJKkyMe26zE2yS+zPW3MDvG9FWgaJzo=;
h=Date:Subject:To:References:From:In-Reply-To;
b=Gxh05UE4ZLYT4kb2JgCb/Kghm0ZTOO/jKGcYcX2RMiTjuggZ+TV050eV4yChxHa3f
5LzF53tsUD21ihcTZOuHFLO3qhnJioPDsA8q8XrWviw6VHJ9Qyw5GLzn1ZvYNDjVse
WXnDLjsIq0ien7jU3AGGentCJsRT7NzcYvzhBcSS4JVEHXDal4lyAKw9XIne2KrA9L
xr6nvdb7C6AY9r2nQvSWXe6WPDKQfyN9XrdVHH1sTNTMdjz3593KPaBFO+wyMRvc8E
wwM7XO5aOy3doLKSr+B2XbT0JyubnctIP196Lk2qtB2LhhLDyzKEF/Yuk06O4HGURN
mMuLkHRMOlvZA==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=NPx2+F6g c=1 sm=1 tr=0 ts=666631b3
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=qEgh2NhK6qfR2VOi:21 a=IkcTkHD0fZMA:10 a=ctex4qzJY_x0heW7hEsA:9
a=QEXdDO2ut3YA:10
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <v456ak$3pmpo$1@dont-email.me>
X-CMAE-Envelope: MS4xfAcSWBmc9UMJdNZl4kTFAH0YoT3fwYs91TPt/gqJA3fyMzeTlEaxibsyp7lTJpSZ7nADWG4xOHs2IA9TcwhvgRggTQcOk3Ab5Qur/U4Y2n6WJ5L2SCsq
B2Tl8FFGm2bw2ME3hfDY5I+bhZDEPZ3hwufqv/Zoqpr3qJIe1tarq7Ga/JN1t4aWLNCL1Gj2m5Oc8rc8HKH+ksjhoIXGdFjXPgA=
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <e149526e-91aa-4dfe-963e-d371ed3d280b@mrabarnett.plus.com>
X-Mailman-Original-References: <v456ak$3pmpo$1@dont-email.me>
View all headers

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.

Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
From: HenHanna
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Sun, 9 Jun 2024 23:16 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
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
View all headers

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)))

Subject: RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Date: Sun, 9 Jun 2024 23:30 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Subject: RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
Date: Sun, 9 Jun 2024 19:30:02 -0400
Lines: 46
Message-ID: <mailman.106.1717975807.2909.python-list@python.org>
References: <v456ak$3pmpo$1@dont-email.me>
<00a801dabac4$f3d463f0$db7d2bd0$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de A6MSJXP3x8Et24DyPj3T6wIPAX04dPxAOydDblNJ+mSw==
Cancel-Lock: sha1:nNtOXzR7Q7aVnVUnscrbUl4yjLA= sha256:5YlfGFwVz5CQ/VF+SfQ6mEJNNXTizqYqqyRsN0z8c/g=
Return-Path: <avi.e.gross@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=IWJhbyon;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.006
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python?': 0.03;
'containing': 0.05; 'fairly': 0.05; 'attempts.': 0.09;
'received:108': 0.09; 'subject:Python': 0.12; 'url:mailman': 0.15;
'(b)': 0.16; '(bar': 0.16; '2024': 0.16; 'tuple': 0.16; 'yield':
0.16; 'message-id:@gmail.com': 0.18; 'to:addr:python-list': 0.20;
'ran': 0.22; 'skip:_ 10': 0.22; 'skip:- 10': 0.25; 'url-
ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'examples': 0.25; 'url:listinfo': 0.25; 'url-ip:188.166/16': 0.25;
'bit': 0.27; 'example,': 0.28; 'suggest': 0.28; 'url-ip:188/8':
0.31; 'collected': 0.32; 'else,': 0.32; 'python-list': 0.32;
'but': 0.32; 'header:In-Reply-To:1': 0.34; 'received:google.com':
0.34; 'bar': 0.35; 'item': 0.35; 'from:addr:gmail.com': 0.35;
'count': 0.36; 'way': 0.38; 'could': 0.38; 'list': 0.39;
'something': 0.40; 'want': 0.40; 'from:': 0.62; 'to:': 0.62;
'copy': 0.63; 'your': 0.64; 'june': 0.73; 'sent:': 0.78; '==>':
0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1717975804; x=1718580604; darn=python.org;
h=content-language:thread-index:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:from:to:cc:subject:date:message-id:reply-to;
bh=fFHcfiVw9iNIz32Fzm6i49o4W2AfbnbVbPZZjYX7pzA=;
b=IWJhbyonii1yaQ+4wDrqwNkpw6TP5TorurzbZ9nRSRsa7rraR4Gw6xEzgFv/hjlNfz
GsumhDMRp01gFFhyP987GI21zN36ltQLPnlf06MzYiBHauoADbE48qFJK5eh9MeSyiz5
FzcPTk2d3W4JCvt4HcZ62fcQsTIfhuo1C1FnrsGwHhVPAsM7OQ48jgSCR/xKr/TXRqtA
1W9W5BSi9L4lylS6uvrxdVjRqKulZ4nHRpZh+wEn9+kCFMWRlSyqB0FldzHmopr/y1+V
b+kBlxGu34aUkfqNL9Z1R+lkVmxP66FRKLN5qw5gkkhKUWx1MsJ63hpm4DCXtP6JYMdX
iXyQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1717975804; x=1718580604;
h=content-language:thread-index:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=fFHcfiVw9iNIz32Fzm6i49o4W2AfbnbVbPZZjYX7pzA=;
b=j/ZP1SPd7syr0SvPNKEVZO+kTQqV2GCPc7oXK1AlbZsG0p3nrbFXV4XV5yVMeD55aG
/aKL6yCXEvZIYW7Tk2AnSWtCuS3w085o5Exp82nxhQzQd2g+Smvbb2J2gXwCe+sqKX6Z
YYJZpNGC9Zo63EgSM1GpYFRZ9jgmUQtFHS/CWVpshHB5cxXMDhi53c5qnFIbOGGPwxDa
fpjZzTswuPQ5tgR7uFHwAnRf64NS/X8z3PCOtxpiEVAkgCBUfE9v24SvDdxQSF0UgcV4
MZrtGOsT1A8PK5QxzOW3/XH6KeNLMcpjjj9hF778q+uzpkK4iUHgBoiofGaYT/phzRey
jH/A==
X-Forwarded-Encrypted: i=1;
AJvYcCVJp8C4heLyQTfujq4FPdbiGDDdpM5mE447ioVUfqhxvhERLtz0goM4T1I1AHRBPEoP6p7cchltr3HFbq/wW6pnN6qb2QG1
X-Gm-Message-State: AOJu0YyqpkJhp4ajX9Gf3Yb47NxopjpurSsWs+eQ4SrRjEsLWz4wLtZ8
QmHSk4nXTRSOYr47d7HmP2UPxrjy8Cf9wCxDRKfdVlkSRpIyCPJc1qSigQ==
X-Google-Smtp-Source: AGHT+IGDsz8SRX4ErcLTW23QpY4DZHT2ZH+skaQgIyap6EEQKf11G0ZxKwMV8imbwW29quH19YkeVQ==
X-Received: by 2002:a05:620a:2415:b0:796:af63:b7c3 with SMTP id
af79cd13be357-796af63beb2mr83055685a.52.1717975804498;
Sun, 09 Jun 2024 16:30:04 -0700 (PDT)
In-Reply-To: <v456ak$3pmpo$1@dont-email.me>
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQJ/EDHgwv9+Eyp+weNGVMwGCTVh87B3aHCw
Content-Language: en-us
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <00a801dabac4$f3d463f0$db7d2bd0$@gmail.com>
X-Mailman-Original-References: <v456ak$3pmpo$1@dont-email.me>
View all headers

HH,

Before bothering, it might be helpful if you spelled out a bit more in the
way of requirements that would satisfy you and perhaps show your attempts.

Your examples suggest it would be fairly simple to create an iterator, for
example, that would yield as it examined one item at a time until it ran out
or the next item was not the same. It could then either return a tuple it
had collected so far since the last yield, or for what you call chunkC,
return a tuple containing one copy of the item and a count of how many.

But if you want something else, such as a list all at once, that too would
be trivial, perhaps leveraging the above.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of HenHanna via Python-list
Sent: Sunday, June 9, 2024 5:20 PM
To: python-list@python.org
Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

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))
--
https://mail.python.org/mailman/listinfo/python-list

Subject: RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Date: Mon, 10 Jun 2024 02:05 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Subject: RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
Date: Sun, 9 Jun 2024 22:05:33 -0400
Lines: 42
Message-ID: <mailman.107.1717985138.2909.python-list@python.org>
References: <v456ak$3pmpo$1@dont-email.me>
<010f01dabada$ad867d00$08937700$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de mqHnzKtFIV5Te+ae2xqZ8APO34ixwweW4RzC4Ihcdpvg==
Cancel-Lock: sha1:qePuBp5f9C+htI6nAfW/+zv/uKo= sha256:iCeU3fuRtLXH7FKPP+wopceasl9LQ1Vs2V+4NnQgq8w=
Return-Path: <avi.e.gross@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=eKxjE2OI;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.082
X-Spam-Evidence: '*H*': 0.84; '*S*': 0.00; 'python?': 0.03;
'received:108': 0.09; 'subject:Python': 0.12; 'url:mailman': 0.15;
'(b)': 0.16; '(bar': 0.16; '2024': 0.16; 'probably': 0.17;
'message-id:@gmail.com': 0.18; 'to:addr:python-list': 0.20;
'language': 0.21; 'skip:_ 10': 0.22; 'code': 0.23; 'past': 0.25;
'skip:- 10': 0.25; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'url-
ip:188.166/16': 0.25; 'perform': 0.26; 'attempt': 0.31; 'url-
ip:188/8': 0.31; 'python-list': 0.32; 'header:In-Reply-To:1':
0.34; 'received:google.com': 0.34; 'bar': 0.35;
'from:addr:gmail.com': 0.35; 'hard': 0.37; 'on.': 0.39; 'explain':
0.40; 'from:': 0.62; 'to:': 0.62; 'showing': 0.62; 'came': 0.65;
'back': 0.67; 'deal': 0.73; 'june': 0.73; 'life': 0.77; 'reply':
0.77; 'sent:': 0.78; '==>': 0.84; 'bounced': 0.84; 'shoot': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1717985136; x=1718589936; darn=python.org;
h=content-language:thread-index:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:from:to:cc:subject:date:message-id:reply-to;
bh=eIBnteW+RVkVVVLSTxKgNNAPVAo6ZORZjfrOXlJDxAY=;
b=eKxjE2OILTDR735uSJZGCC5LUJQVWW+vHuHjA7Mr9BlF+z0A2mN+gy2H/wB8Ovboly
zgZ0bJCukGBqFMjR3ura+edz7fu3LBtYXCz3pwr3s21owPjW5714vc3PCFcZgFqHfZs/
eGBCN4FrXZyHwnz6GllPgXFy6oatnGw5tyW/vq7BfFCBEoOy+Rqmn7yZy63z11EERMAW
WgwX5kTnwC10ittVHLAFGN2WIwbhxMUg/9Ai9NSVpNqee5o5PWQTufTOGVhegRiPbVL1
WTKF4PneRBVaxuK81h2mOPwhfFqBJ4QesOUV6njwAWu2Kt971QGgRlVaK26oQeSkssHU
UQnQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1717985136; x=1718589936;
h=content-language:thread-index:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=eIBnteW+RVkVVVLSTxKgNNAPVAo6ZORZjfrOXlJDxAY=;
b=T8io2Filf3JZSijiZhfdsYbDSXQ1xlAFK+xTxPM+pZocL7ESWcbgyLpJmp/vIem81n
4UbVnFxqj5xFItAkBBc02zlmbFLaXnfve1uxrKFGYp/AYYHopvVYmeJrUq/jgJNnvth7
jGvvA75wO6IkYeEjBvlbjtDK2xAAXGRXPQA7A5B8z/5IMYpZkr0Ox4rAQg8BwFSTniwT
SLSA0IYz7O/hM//gWUKYchwHsm3ZxI58/vuUNrLetyItW0snkLKxpFLTiFFIBhjRZ1PV
9VCIb74aeVY3Y+bNvcE1KOD82rwnVpuNY43FsxXfv3zL7XrGTcK4N2epmnpHddPJEfI9
Cm/Q==
X-Gm-Message-State: AOJu0Yxvi+VSojkxH3M6R9JnE/Nv7qK3oOBz+KUayYDV6O12r4Kskq2D
epd0CrWTG1Z5sxkzyULdxi79udNCB5yqXaRmteNg9xTvTnd98KZ57Tb9Sw==
X-Google-Smtp-Source: AGHT+IGQDtCJs+9PLS1t9f7jtD80TnihsH3sprj6TdOZQ1GIsVeEotYGP4kFAfNGZrxkrt8mYAxOag==
X-Received: by 2002:a05:6808:f87:b0:3d2:1f71:1901 with SMTP id
5614622812f47-3d21f711a37mr5131651b6e.29.1717985135570;
Sun, 09 Jun 2024 19:05:35 -0700 (PDT)
In-Reply-To: <v456ak$3pmpo$1@dont-email.me>
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQJ/EDHgwv9+Eyp+weNGVMwGCTVh87B3lCAQ
Content-Language: en-us
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <010f01dabada$ad867d00$08937700$@gmail.com>
X-Mailman-Original-References: <v456ak$3pmpo$1@dont-email.me>
View all headers

I remembered that HenHanna had been hard to deal with in the past and when
my reply to him/her/them bounced as a bad/fake address it came back to me
that I am better off not participating in this latest attempt to get us to
perform then probably shoot whatever we say down.

A considerate person would ask questions more clearly and perhaps explain
what language they are showing us code from and so on.

Life is too short to waste.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of HenHanna via Python-list
Sent: Sunday, June 9, 2024 5:20 PM
To: python-list@python.org
Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

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))
--
https://mail.python.org/mailman/listinfo/python-list

Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
From: HenHanna
Newsgroups: comp.lang.python, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Mon, 10 Jun 2024 02:36 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.python,comp.lang.scheme
Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
Date: Sun, 9 Jun 2024 19:36:39 -0700
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <v45orn$3j3r$1@dont-email.me>
References: <v456ak$3pmpo$1@dont-email.me>
<010f01dabada$ad867d00$08937700$@gmail.com>
<mailman.107.1717985138.2909.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 10 Jun 2024 04:36:39 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="fdf3da398add0912fb8385f840f76bc6";
logging-data="117883"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bK2n1djS+ZUchocHY2Dgc4+SwOKLLbCU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:WrcDxmKxLcaO8Vtc1njlCwZQPBk=
Content-Language: en-US
In-Reply-To: <mailman.107.1717985138.2909.python-list@python.org>
View all headers

On 6/9/2024 7:05 PM, avi.e.gross@gmail.com wrote:
> I remembered that HenHanna had been hard to deal with in the past and when
> my reply to him/her/them bounced as a bad/fake address it came back to me
> that I am better off not participating in this latest attempt to get us to
> perform then probably shoot whatever we say down.
>
> A considerate person would ask questions more clearly and perhaps explain
> what language they are showing us code from and so on.
>
> Life is too short to waste.
>
> -----Original Message-----
> From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
> Behalf Of HenHanna via Python-list
> Sent: Sunday, June 9, 2024 5:20 PM
> To: python-list@python.org
> Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
>
> 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))

i was just curiuos about simple, clever way to write it in Python

in 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)))

(define (gpC x) (map (lambda (x) (list (car x) (length x))) (gp x)))

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

Subject: RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Date: Mon, 10 Jun 2024 18:07 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Subject: RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
Date: Mon, 10 Jun 2024 14:07:38 -0400
Lines: 139
Message-ID: <mailman.108.1718042862.2909.python-list@python.org>
References: <v456ak$3pmpo$1@dont-email.me>
<010f01dabada$ad867d00$08937700$@gmail.com>
<mailman.107.1717985138.2909.python-list@python.org>
<v45orn$3j3r$1@dont-email.me>
<00b901dabb61$1428a200$3c79e600$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 4WxQkkhqKTCNn3wJWgC6dQiEMmxIzNjnRUEYAXYJReVQ==
Cancel-Lock: sha1:NIL8dp73KZ+uydTGi+TC6Vk+eAM= sha256:C8TtX2khdrDWDQ559qP0hljl5+d73vrFLa93DbSfp5s=
Return-Path: <avi.e.gross@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=k1x/BrPl;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.013
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'python?': 0.03;
'containing': 0.05; 'row': 0.05; 'suggestion': 0.07; 'deeper':
0.09; 'enough.': 0.09; 'numpy': 0.09; 'order,': 0.09;
'received:108': 0.09; 'supplied': 0.09; 'trivial': 0.09;
'subject:Python': 0.12; 'url:mailman': 0.15; '(b)': 0.16; '(bar':
0.16; '2024': 0.16; 'arbitrary': 0.16; 'comparing': 0.16;
'compiled': 0.16; 'found,': 0.16; 'item,': 0.16; 'levels?': 0.16;
'loops': 0.16; 'matched': 0.16; 'nothing,': 0.16; 'prime': 0.16;
'purpose?': 0.16; 'tries': 0.16; 'yield': 0.16; 'wrote:': 0.16;
'python': 0.16; 'probably': 0.17; 'message-id:@gmail.com': 0.18;
'implement': 0.19; 'pm,': 0.19; 'to:addr:python-list': 0.20;
'language': 0.21; 'written': 0.22; 'languages': 0.22; 'first,':
0.22; 'maybe': 0.22; 'returns': 0.22; 'skip:_ 10': 0.22; 'code':
0.23; 'run': 0.23; 'anything': 0.25; 'past': 0.25; 'skip:- 10':
0.25; 'url-ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24':
0.25; 'python,': 0.25; 'depends': 0.25; 'examples': 0.25;
'url:listinfo': 0.25; 'programming': 0.25; 'url-ip:188.166/16':
0.25; 'seems': 0.26; 'again,': 0.26; 'object': 0.26; 'perform':
0.26; 'function': 0.27; 'done': 0.28; 'sense': 0.28; 'ideas':
0.28; 'asked': 0.29; 'it,': 0.29; 'attempt': 0.31; 'looked': 0.31;
'url-ip:188/8': 0.31; 'think': 0.32; 'empty': 0.32; 'python-list':
0.32; 'same,': 0.32; 'simple,': 0.32; 'but': 0.32; 'there': 0.33;
'same': 0.34; 'mean': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'bar': 0.35; 'item': 0.35; 'usual':
0.35; 'yes,': 0.35; 'from:addr:gmail.com': 0.35; 'using': 0.37;
'hard': 0.37; 'others': 0.37; 'way': 0.38; 'means': 0.38;
'error,': 0.38; 'otherwise': 0.39; 'handle': 0.39; 'list': 0.39;
'methods': 0.39; 'much.': 0.39; 'on.': 0.39; 'explain': 0.40;
'match': 0.40; 'something': 0.40; 'want': 0.40; 'should': 0.40;
'including': 0.60; 'from:': 0.62; 'to:': 0.62; 'showing': 0.62;
'email addr:gmail.com': 0.63; 'copy': 0.63; 'full': 0.64;
'extend': 0.64; 're:': 0.64; 'your': 0.64; 'top': 0.65; 'came':
0.65; 'required': 0.65; 'less': 0.65; 'numbers': 0.67; 'back':
0.67; 'bad': 0.67; 'exactly': 0.68; 'items': 0.68; 'and,': 0.69;
'functional': 0.69; 'remaining': 0.69; 'compared': 0.71; 'deal':
0.73; 'june': 0.73; 'easy': 0.74; '1.0': 0.76; 'delivers': 0.76;
'life': 0.77; 'reply': 0.77; 'sent:': 0.78; '==>': 0.84; 'ask,':
0.84; 'bounced': 0.84; 'container,': 0.84; 'flat': 0.84;
'further.': 0.84; 'handed': 0.84; 'shoot': 0.84; 'subtle': 0.84;
'consecutive': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1718042859; x=1718647659; darn=python.org;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:from:to:cc:subject:date:message-id:reply-to;
bh=0Hl7om+CjTksj+K4qLNrbd9sFmaIsPGxUcnZnZXW6pc=;
b=k1x/BrPlN0OYKbzc/lIX4B3z0eoYnrmdzw3T/wU3Zs3o/X5YrGn8dg7up4/gQ5DmDz
ScQ4InT4yw/jUQGqX1/vsXQAW5Tuq6ByNAtvE6z1bGNSu/IodfABmisvOMZ+SgFsWGcP
EBAzBIZPd7NpS3KuHgPH7z60/KAjS8dh+Hpy7I65omo8hwv/90ncfSbONR1E60zVRdfm
jUuTejIQoUKdAkcvd4NrjjbaYxZiLy44IqLveZBKGizzFtAY0SNqcYdJGx8SMaGA5VCc
Vbqte30a5SyefOvIyxUP004SNwmWXZgRgtv/ZLXXQCiBICRQn6Iol5F92gRskWC9akoy
fFxw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1718042860; x=1718647660;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=0Hl7om+CjTksj+K4qLNrbd9sFmaIsPGxUcnZnZXW6pc=;
b=PxKrtUl28f61pzP1wbPt+/I9uiXVMByjnGL1Hts1IVX5VUvEf01BNdMko1Maa8bEbs
CMF9vXT02Ic8jZH3KUPDvQBgD6l/Bcz5OrS2AhB+ExrmEZwEupHZDIu+ddSy4M2Ds3PV
bExFfcQDr6Ny8Nb4zHHfRWz5HYZ1KFMJQaqpbe4eRNLN98HXMZXKk/FDui3gNHc2y7KQ
8npo2OUjFvzqeST34sFggUhZEGyCIsw15cgwfyXYINklaPhitlKGY0BmmmFcLqtFrJpL
AOj+Zmow/d9Z1G/era3K16+39QNxYeq0HOMzOs862gSUen+LcVnDBPrDtuM53bDaAjha
Qrgg==
X-Gm-Message-State: AOJu0Yy3X1VAo9TgaIXOVSLxo5zG2KjNwFrvyDJLL5YYCXnpxclorXwf
naCCqxZVyc+pCkmYS0mvE1P7XQupV/K3MglLMSVa+ZtIFPKcKpssH5a38Q==
X-Google-Smtp-Source: AGHT+IHqZf8wXeXZlnJxXGYUF60j3CDbT6N3JNfE09NbVaRaYRoQWXP05Q0BGmQCjngl2GixwCsyPQ==
X-Received: by 2002:a05:6214:5505:b0:6b0:6fc6:25d0 with SMTP id
6a1803df08f44-6b06fc62786mr82602566d6.13.1718042859131;
Mon, 10 Jun 2024 11:07:39 -0700 (PDT)
In-Reply-To: <v45orn$3j3r$1@dont-email.me>
X-Mailer: Microsoft Outlook 16.0
Content-Language: en-us
Thread-Index: AQJ/EDHgwv9+Eyp+weNGVMwGCTVh8wK45EUCAi0n4sYBlZzyh7BEqOsg
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <00b901dabb61$1428a200$3c79e600$@gmail.com>
X-Mailman-Original-References: <v456ak$3pmpo$1@dont-email.me>
<010f01dabada$ad867d00$08937700$@gmail.com>
<mailman.107.1717985138.2909.python-list@python.org>
<v45orn$3j3r$1@dont-email.me>
View all headers

> i was just curiuos about simple, clever way to write it in Python

It depends on what you mean by "clever".

For some, it was like a suggestion on using something already available such
as itertools.groupby, perhaps even better if it is actually compiled in from
a language like C and perhaps more efficient.

For some who like to Scheme, only a recursive solution may be considered
clever!

For some who have absorbed ideas in languages like python, perhaps they
would implement it the way I described as an iterator that is efficient in
the sense that it delivers things just in time and quits if not iterated
further. An example might be if you asked to get groups of consecutive
digits in the calculated indefinite value of a number like pi or e or looked
at how many digits in a row were the same for prime numbers but wanted to
quit after the first billion.

Some may like some kind of functional programming method. Some want short
code and some want efficiency and some even like something written in a
subtle way so others have trouble understanding it, as in the obfuscated C
contests.

What you do need to consider is what exactly are your requirements. Your
examples are trivial so maybe we need to think about what it means to gather
together what is supplied in one container, into a container containing
other grouped containers.

First, what python containers should be handled? Yes, you probably mean a
list but if handed a tuple, should it return the same, or always return a
list for the top level and perhaps even deeper levels? There are many
containers in python including (ordered) dictionaries where the keys may be
unique, but you may want to see if the contents have some order, numpy
arrays, and so on.

And, are all the contents required to be atomic? What does it mean for items
in a row to be equal? If I have a sublist, should I unlist to make it flat
first, or should it be an error, or should each such sublist be compared for
full equality or even relative equality so that (a (b c) (c b) d) actually
accepts (b c) and (c b) as the same for the purpose? For that matter, is 1.0
matched to 1 or even "1" or perhaps an object that has that value in some
way such as when comparing arbitrary objects?

There can be many such questions and some elegant methods get less elegant
if they need to handle too much. You need to explain what to do when a bad
unintended case is found, such as perhaps an empty list or ...

To just do what your examples ask, again, seems easy enough. It is the usual
code if not done too elegantly. Write a function that accepts a list (or
tries to coerce what it gets into a copy as a list. It returns an empty list
if it has nothing, otherwise pops off the first item and then loops on the
rest. When items match the current first item, extend a sublist and when
they don't, yield what you have and start a new sublist. After the loop,
anything remaining is returned.

Simple enough?

Note to get your result properly, since it is an iterator, you need to
either be calling it iteratively, or do something like:

Result = list(chunk(something))

To force it to run to completion.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of HenHanna via Python-list
Sent: Sunday, June 9, 2024 10:37 PM
To: python-list@python.org
Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

On 6/9/2024 7:05 PM, avi.e.gross@gmail.com wrote:
> I remembered that HenHanna had been hard to deal with in the past and when
> my reply to him/her/them bounced as a bad/fake address it came back to me
> that I am better off not participating in this latest attempt to get us to
> perform then probably shoot whatever we say down.
>
> A considerate person would ask questions more clearly and perhaps explain
> what language they are showing us code from and so on.
>
> Life is too short to waste.
>
> -----Original Message-----
> From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org>
On
> Behalf Of HenHanna via Python-list
> Sent: Sunday, June 9, 2024 5:20 PM
> To: python-list@python.org
> Subject: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
>
> 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))

i was just curiuos about simple, clever way to write it in Python

in 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)))

(define (gpC x) (map (lambda (x) (list (car x) (length x))) (gp x)))

(print (gpC '(a b b a a a b b b b)))
(print (gpC '(c c c a d d d d a e e e e e)))
--
https://mail.python.org/mailman/listinfo/python-list

Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
From: Rob Cliffe
Newsgroups: comp.lang.python
Date: Mon, 10 Jun 2024 13:29 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: rob.cliffe@btinternet.com (Rob Cliffe)
Newsgroups: comp.lang.python
Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
Date: Mon, 10 Jun 2024 14:29:08 +0100
Lines: 42
Message-ID: <mailman.109.1718115170.2909.python-list@python.org>
References: <v456ak$3pmpo$1@dont-email.me>
<91823458-bc96-4725-8d9e-35c9c687c5d2@btinternet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de vKppJr9HgJV8UeWLlBb1tQdzVGbDBCqeF3RMiQF8/uqw==
Cancel-Lock: sha1:rh66PNq+SG0OiqezI/tMDktcKrw= sha256:bwanHSEhYDv5mSFk+GzFIBAdma9v4AAnyxMIfvLdVag=
Return-Path: <rob.cliffe@btinternet.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=btinternet.com header.i=@btinternet.com header.b=SfZ3d9mx;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python?': 0.03; 'def':
0.04; 'output:': 0.09; 'skip:# 30': 0.09; 'subject:Python': 0.12;
'import': 0.15; '(b)': 0.16; '(bar': 0.16; 'itertools': 0.16;
'wrote:': 0.16; 'to:addr:python-list': 0.20; 'skip:_ 10': 0.22;
'header:User-Agent:1': 0.30; 'program': 0.31; 'python-list': 0.32;
'received:192.168.1': 0.32; 'header:In-Reply-To:1': 0.34; 'bar':
0.35; 'received:192.168': 0.37; 'received:213': 0.40; 'skip:i 20':
0.62; '==>': 0.84; 'rob': 0.84;
'\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com;
s=btmx201904; t=1718026149;
bh=sVFRoYd7nL/SbU/xAPIklunVL3j/lXltsHRypSXc6FM=;
h=Message-ID:Date:MIME-Version:Subject:To:References:From:In-Reply-To;
b=SfZ3d9mxgAbQURqXVgzYkbEANMPKHI2VqCH0ko7PQngCbIlS29dw+RYy6m0C3odu0V5viwaf8QKTlnf6ucofg5yZx3KQadVqHGbGC8gXfkiEJKmve29FcpmsQ0fTem94dmET0ek/i2dVIahv8MSq26VxjddcQ1FkAXyOMU6eme6Zq4wG8FECKTjJEvwdp9mhL+1Qm7swj2wFTU9nn0KyYmn63SD4DNuNWMvPrQi21TXDLls3VNRID1z/BijVAhE/70mrmTJLqGGFmec0WzXYznm4yTj7c80Ti8X0FeimwisvcHBqchYK0BE8wIKqK/U1mMlH2gxUCRnPiR1mJtuFbg==
Authentication-Results: btinternet.com;
auth=pass (PLAIN) smtp.auth=rob.cliffe@btinternet.com;
bimi=skipped
X-SNCR-Rigid: 65A567CD1065E9F9
X-Originating-IP: [86.184.143.52]
X-OWM-Source-IP: 86.184.143.52
X-OWM-Env-Sender: rob.cliffe@btinternet.com
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvledrfedutddgieegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomheptfhosgcuvehlihhffhgvuceorhhosgdrtghlihhffhgvsegsthhinhhtvghrnhgvthdrtghomheqnecuggftrfgrthhtvghrnhepteetueffteffgeetffehveehjeduffekleetudevkeetkeehteevudejgeekheevnecukfhppeekiedrudekgedrudegfedrhedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplgduledvrdduieekrddurddvtdekngdpihhnvghtpeekiedrudekgedrudegfedrhedvpdhmrghilhhfrhhomheprhhosgdrtghlihhffhgvsegsthhinhhtvghrnhgvthdrtghomhdpnhgspghrtghpthhtohepuddprhgtphhtthhopehphihthhhonhdqlhhishhtsehphihthhhonhdrohhrghdprhgvvhfkrfephhhoshhtkeeiqddukeegqddugeefqdehvddrrhgrnhhgvgekiedqudekgedrsghttggvnhhtrhgrlhhplhhushdrtghomhdprghuthhhpghushgvrheprhhosgdrtghlihhffhgvsegsthhinhhtvghrnhgvthdrtghomhdpghgvohfkrfepifeupdfovfetjfhoshhtpehsrgdqphhrugdqrhhgohhuthdqtddtvd
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-SNCR-hdrdom: btinternet.com
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <v456ak$3pmpo$1@dont-email.me>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <91823458-bc96-4725-8d9e-35c9c687c5d2@btinternet.com>
X-Mailman-Original-References: <v456ak$3pmpo$1@dont-email.me>
View all headers

import itertools

def chunk1(seq):
    return [ ch * len(list(grp)) for (ch, grp) in itertools.groupby(s) ]

def chunk2(seq):
    return [ (ch, len(list(grp))) for (ch, grp) in itertools.groupby(s) ]

s='aaabbccccaa'
print(chunk1(s))
print(chunk2(s))
###################################
Program output:
['aaa', 'bb', 'cccc', 'aa']
[('a', 3), ('b', 2), ('c', 4), ('a', 2)]

Rob Cliffe

On 09/06/2024 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))

Subject: RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Date: Tue, 11 Jun 2024 18:13 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Subject: RE: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
Date: Tue, 11 Jun 2024 14:13:08 -0400
Lines: 121
Message-ID: <mailman.110.1718129592.2909.python-list@python.org>
References: <v456ak$3pmpo$1@dont-email.me>
<91823458-bc96-4725-8d9e-35c9c687c5d2@btinternet.com>
<004701dabc2b$032d3180$09879480$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de NxLJX1B/uylMu/D44C/3AQXzQl9KKjqc9gpCwBsLPwZw==
Cancel-Lock: sha1:AAi6610nrSfqMG7r/L9eSjigv1Y= sha256:hL46baXUujJgYISzbrs6ZO90kn8YeQ873YAPSEeyIUw=
Return-Path: <avi.e.gross@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=KgUZ2820;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'comments': 0.03;
'python?': 0.03; 'def': 0.04; 'containing': 0.05; 'fairly': 0.05;
'loop': 0.07; 'elif': 0.09; 'else:': 0.09; 'fun,': 0.09;
'output:': 0.09; 'received:108': 0.09; 'skip:# 30': 0.09;
'subject:Python': 0.12; 'import': 0.15; 'url:mailman': 0.15;
'(b)': 0.16; '(bar': 0.16; '2024': 0.16; 'completion': 0.16;
'initialize': 0.16; 'instances.': 0.16; 'itertools': 0.16;
'presumably': 0.16; 'tuple': 0.16; 'tuples': 0.16; 'yield': 0.16;
'wrote:': 0.16; 'probably': 0.17; 'message-id:@gmail.com': 0.18;
'to:addr:python-list': 0.20; 'input': 0.21; 'focused': 0.22;
'skip:_ 10': 0.22; 'version': 0.23; 'code': 0.23; 'run': 0.23;
'skip:- 10': 0.25; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'examples': 0.25; 'url:listinfo': 0.25;
'url-ip:188.166/16': 0.25; 'creating': 0.27; 'function': 0.27;
'>>>': 0.28; 'purpose': 0.28; 'it,': 0.29; 'code,': 0.31; 'url-
ip:188/8': 0.31; 'program': 0.31; 'empty': 0.32; 'needed,': 0.32;
'python-list': 0.32; 'but': 0.32; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'bar': 0.35; 'item': 0.35; 'runs':
0.35; 'from:addr:gmail.com': 0.35; 'functions': 0.36; 'lists':
0.37; "skip:' 10": 0.37; 'using': 0.37; 'way': 0.38; 'could':
0.38; 'means': 0.38; 'added': 0.39; 'handle': 0.39; 'list': 0.39;
'copy.': 0.40; '10,': 0.61; 'from:': 0.62; 'to:': 0.62; 'skip:i
20': 0.62; 'mode': 0.62; 'once': 0.63; 're:': 0.64; 'produce':
0.65; 'named': 0.65; 'items': 0.68; 'matter': 0.68; 'remaining':
0.69; 'within': 0.69; 'below': 0.69; 'june': 0.73; 'skip:y 10':
0.76; 'produces': 0.76; 'requested': 0.76; 'sent:': 0.78;
'returned': 0.81; '==>': 0.84; 'adjusted': 0.84; 'bothered': 0.84;
'rob': 0.84; 'was.': 0.84; 'operates': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1718129589; x=1718734389; darn=python.org;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:from:to:cc:subject:date:message-id:reply-to;
bh=oaVCnTOOt43f+VXMYjaLxy8C3zgB6DB7m96iVP1beko=;
b=KgUZ2820Po41rj0TrghRDFCtRNpvqFedm1IgU+YHb0ca5NoLDCT3frGaDLzXIxDg51
kS3POvNX6yQpsJbQEXCoPvV9GLiGTqSFXLF2YFoLD5L4j3BzsaCxIF8Acd5xInFvx0hv
I8RAJoRX8p1e8mTGjICbf0JsoKN9CREOKHdFtGqgQpnj/TfavlOesUJgR89QHGxDDQCV
zudDdythwslIkSlwwpFw6e/x1tc67/VuCMPrcHTfvTMudsVJoiV1q1e3fLfnD/h6PgnY
koCTmuoThmO+Qip8USqwWpuz+E+XqOhcd43nHVFqOb7R51Z3t5D5cx/GAakjc8PVbFcl
2Z6Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1718129589; x=1718734389;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=oaVCnTOOt43f+VXMYjaLxy8C3zgB6DB7m96iVP1beko=;
b=hXbiSqhsJ+gD5qOfd4AYFBRmQ1EPJtBZqYgkctS5UcsXdIdkwdEaAN+yuZQ01c1m+3
dK/iWEsyjfoV47b55wfiH30J8RwXapK8dMrzeNxZd4zn44ps1+S0b5fMoglBU2qZ0xOz
Hn70kkqAF8XHMJFncX5uLZXgu/k2mgLJgQwPmQVj3q/zk+cDIRioT7NLrPTIRTbbHru0
dcdmOEbd+IpDHeL0C/V3GTi3eKBh+aYjDVWWnf2l+8lieuvyvOuyi1KgX4auIQQe2xxf
6KELjVhKvGNhubuLewn6rQ9idBKG168gOBiITvxc3xdTM5jNpQex2OB3Sru3kV21CaLj
741Q==
X-Forwarded-Encrypted: i=1;
AJvYcCVJ797i3rkF9/OO9i3qUuG4JGE/yK4a1N1F6vux8e0Y7rk49bPWkRb6OXSIpdb7GhdJwCpRRhvhn7loVUNjCA+4ayiVQiHY
X-Gm-Message-State: AOJu0Yw4ruUTLeSHJKL+Ff/0NBWOR1w1Avl4TZUXEw2U3weMBHP2mvuV
laFcPUSfDurcls84DxLoPHey/wSYKZKujn0n4WPBY40rwt+F3v5l1nCSUg==
X-Google-Smtp-Source: AGHT+IFLMaecBYWZNMEDlYqhgSZ4grs+1aVsc/3RcbQrwas1PcTVXvDeD9fiJ2nswrQNR6sCE/ix2A==
X-Received: by 2002:a05:6358:54a2:b0:19f:4967:4e8f with SMTP id
e5c5f4694b2df-19f49675529mr1088245955d.22.1718129588703;
Tue, 11 Jun 2024 11:13:08 -0700 (PDT)
In-Reply-To: <91823458-bc96-4725-8d9e-35c9c687c5d2@btinternet.com>
X-Mailer: Microsoft Outlook 16.0
Content-Language: en-us
Thread-Index: AQJ/EDHgwv9+Eyp+weNGVMwGCTVh8wKk66fHsGUK5PA=
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <004701dabc2b$032d3180$09879480$@gmail.com>
X-Mailman-Original-References: <v456ak$3pmpo$1@dont-email.me>
<91823458-bc96-4725-8d9e-35c9c687c5d2@btinternet.com>
View all headers

Rob,

That is a fairly straightforward and elegant solution if using an added mode called itertools.

I went a different way by creating my own focused iterator and calling it, when needed, to produce one or the other of the results requested in the functions named chunk() and chunkc(). But note my version operates to produce lists no matter what the input was. It produces lists nestled within lists. Presumably it could be adjusted to check if the input was a tuple and then return a grouping of tuples within a tuple.

The code, just for fun, is below and probably could be more elegant! LOL!

### CODE START

# Iterator version to be called as needed or all at once as with ChunkC
def ChunkIterator(seq):
# Purpose is to evaluate a list and return a list
# of lists with each one containing the longest run
# of each item.

# Handle an empty list
if len(seq) == 0: return container

# Initialize the first item in a copy.
# The first item is now in a initialized list.
gathered = [last := seq[0]]

# Loop over the remaining items and yield as needed.
for item in seq[1:]:
if len(gathered) == 0: gathered = [item]
elif item == last: gathered.append(item)
else: # not equal means yield result and start anew for next group
yield(gathered)
gathered = [last := item]

# After loop completes, any remaining data is returned as the function terminates.
if len(gathered) > 0: yield(gathered)

# Accesory function that runs the iterator to completion into a list.
def Chunk(seq): return list(ChunkIterator(seq))

# Function that simplifies the Chunks as an item and a number of instances.
def ChunkC(seq):
return [[group[0], len(group)] for group in ChunkIterator(seq)]
### CODE END

### EXAMPLES
>>> tuple(Chunk([1, 2, 2, 'c', 'c', 'c', 'singleton']))
([1], [2, 2], ['c', 'c', 'c'], ['singleton'])
>>> chunk([1, 2, 2, 'c', 'c', 'c', 'singleton'])
[[1], [2, 2], ['c', 'c', 'c'], ['singleton']]
>>> chunkC([1, 2, 2, 'c', 'c', 'c', 'singleton'])
[[1, 1], [2, 2], ['c', 3], ['singleton', 1]]

# COMMENTS
The current version has flaws I have not bothered correcting. Just for a demo.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Rob Cliffe via Python-list
Sent: Monday, June 10, 2024 9:29 AM
To: python-list@python.org
Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

import itertools

def chunk1(seq):
return [ ch * len(list(grp)) for (ch, grp) in itertools.groupby(s) ]

def chunk2(seq):
return [ (ch, len(list(grp))) for (ch, grp) in itertools.groupby(s) ]

s='aaabbccccaa'
print(chunk1(s))
print(chunk2(s))
###################################
Program output:
['aaa', 'bb', 'cccc', 'aa']
[('a', 3), ('b', 2), ('c', 4), ('a', 2)]

Rob Cliffe

On 09/06/2024 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))

--
https://mail.python.org/mailman/listinfo/python-list

Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
From: HenHanna
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Tue, 11 Jun 2024 22:07 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.python
Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
Date: Tue, 11 Jun 2024 15:07:34 -0700
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <v4ahr6$182gf$3@dont-email.me>
References: <v456ak$3pmpo$1@dont-email.me>
<91823458-bc96-4725-8d9e-35c9c687c5d2@btinternet.com>
<mailman.109.1718115170.2909.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 12 Jun 2024 00:07:34 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ccb0f6b9ea4c672876c3c6f90f002985";
logging-data="1313295"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18h6VBdTiQ5RIfiyfKNe6EV4a9QagLHhG0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:bvxuTb2JAk8e6GCy0BbT3EvrC7A=
Content-Language: en-US
In-Reply-To: <mailman.109.1718115170.2909.python-list@python.org>
View all headers

On 6/10/2024 6:29 AM, Rob Cliffe wrote:
> import itertools
>
> def chunk1(seq):
>     return [ ch * len(list(grp)) for (ch, grp) in itertools.groupby(s) ]
>
> def chunk2(seq):
>     return [ (ch, len(list(grp))) for (ch, grp) in itertools.groupby(s) ]
>
> s='aaabbccccaa'
> print(chunk1(s))
> print(chunk2(s))
> ###################################
> Program output:
> ['aaa', 'bb', 'cccc', 'aa']
> [('a', 3), ('b', 2), ('c', 4), ('a', 2)]
>
> Rob Cliffe
>

thank you... OMG... For 10 minutes... i was SO mystified by
the question...
How can this code work??? , when it's
> def chunk1(seq):
and it's [s] within the def-body ?

it seemed as if the Compiler was doing a DWIM (Do what i mean) trick.

> On 09/06/2024 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))
>

Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
From: B. Pym
Newsgroups: comp.lang.python, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sat, 15 Jun 2024 02:53 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.python,comp.lang.scheme
Subject: Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))
Date: Sat, 15 Jun 2024 02:53:52 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <v4ivnt$39hbo$1@dont-email.me>
References: <v456ak$3pmpo$1@dont-email.me> <010f01dabada$ad867d00$08937700$@gmail.com> <mailman.107.1717985138.2909.python-list@python.org> <v45orn$3j3r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Date: Sat, 15 Jun 2024 04:53:53 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="fbdbd461b6d50fc87347a01f45a4822c";
logging-data="3458424"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wpwqbOrFoH1PJPLBGVdna"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:9r91LkFqomCPN26GlB+I9Gae9UI=
View all headers

On 6/9/2024, HenHanna wrote:

> > (Chunk '(a a b a a a b b))
> > ==> ((a a) (b) (a a a) (b b))
> >

Gauche Scheme:

(use gauche.sequence)

(group-sequence '(2 4 4 3 0 5 8 6 6 6))
===>
((2) (4 4) (3) (0) (5) (8) (6 6 6))

1

rocksolid light 0.9.8
clearnet tor