Sujet : Re: A missing iterator on itertools module?
De : none (at) *nospam* none.fr (ast)
Groupes : comp.lang.pythonDate : 28. Mar 2024, 19:12:54
Autres entêtes
Organisation : Guest of ProXad - France
Message-ID : <6605a515$0$2578$426a74cc@news.free.fr>
References : 1 2
User-Agent : Mozilla Thunderbird
Le 28/03/2024 à 18:07, Stefan Ram a écrit :
ast <none@none.fr> wrote or quoted:
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.
So I came up with this solution:
list(chain.from_iterable(zip("AZERTY", "QSDFGH", "WXCVBN")))
Maybe you meant "zip(s1,s2,s3)" as the definition of s1, s2,
and s3 otherwise would not be required. Also the "list" is not
necessary because "chain.from_iterable" already is an iterable.
You could also use "*" instead of "list" to print it. So,
import itertools as _itertools
s =[ "AZERTY", "QSDFGH", "WXCVBN" ]
print( *_itertools.chain.from_iterable( zip( *s )))
. But these are only minor nitpicks; you have found a nice solution!
Why did you renamed itertools as _itertools ?