Sujet : Re: A missing iterator on itertools module?
De : antoon.pardon (at) *nospam* vub.be (Antoon Pardon)
Groupes : comp.lang.pythonDate : 03. Apr 2024, 10:11:01
Autres entêtes
Message-ID : <mailman.60.1712135466.3468.python-list@python.org>
References : 1 2
User-Agent : Mozilla Thunderbird
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.