RE: A missing iterator on itertools module?

Liste des GroupesRevenir à cl python 
Sujet : RE: A missing iterator on itertools module?
De : <avi.e.gross (at) *nospam* gmail.com>
Groupes : comp.lang.python
Date : 03. Apr 2024, 13:14:53
Autres entêtes
Message-ID : <mailman.61.1712146500.3468.python-list@python.org>
References : 1 2 3
User-Agent : Microsoft Outlook 16.0
Antoon,

Even if the suggested solution offers a partial result, you would need
specific requirements to determine what should be done if one or more of the
parts being cycled is shorter than the others. Stopping at that point is one
option. Another is to continue but only interleave ones still producing and
in the same order.

There is a function in itertools called zip_longest() that might be
considered as it keeps going but substitutes a customizable value for
"missing" parts. You could then, perhaps, make a change so that sentinel is
not passed  along.


-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of Antoon Pardon via Python-list
Sent: Wednesday, April 3, 2024 5:11 AM
To: python-list@python.org
Subject: Re: A missing iterator on itertools module?



Op 28/03/2024 om 17:45 schreef ast via Python-list:
Hello
>
Suppose I have these 3 strings:
>
s1 = "AZERTY"
s2 = "QSDFGH"
s3 = "WXCVBN"
>
and I need an itertor who delivers
>
A Q W Z S C E D C ...
>
I didn't found anything in itertools to do the job.

The documentation mentions a roundrobin recipe.
>
So I came up with this solution:
>
>
list(chain.from_iterable(zip("AZERTY", "QSDFGH", "WXCVBN")))
>
['A', 'Q', 'W', 'Z', 'S', 'X', 'E', 'D', 'C', 'R', 'F', 'V', 'T', 'G',
'B', 'Y', 'H', 'N']

But if your strings are not equal, this will only produce a partial result.
--
https://mail.python.org/mailman/listinfo/python-list


Date Sujet#  Auteur
28 Mar 24 * A missing iterator on itertools module?9ast
28 Mar 24 +- Re: A missing iterator on itertools module?1ast
28 Mar 24 +* Re: A missing iterator on itertools module?5Stefan Ram
28 Mar 24 i`* Re: A missing iterator on itertools module?4ast
28 Mar 24 i `* Re: A missing iterator on itertools module?3Stefan Ram
29 Mar 24 i  +- Re: A missing iterator on itertools module? (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
29 Mar 24 i  `- Re: A missing iterator on itertools module?1Mark Bourne
3 Apr 24 +- Re: A missing iterator on itertools module?1Antoon Pardon
3 Apr 24 `- Re: A missing iterator on itertools module?1<avi.e.gross

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal