A Q W Z S C E D C ...
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")))
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 ?
ast <none@none.fr> wrote or quoted:
Why did you renamed itertools as _itertools ?
Assume I have a module A.py:
import math
def f(): pass
. Assume I have an additional module B.py:
import A
. Now, when I'm editing "B.py" in IDLE and type "A.", IIRC
IDLE will offer me two possible completions: "A.math" and
"A.f". The "A.math" makes no sense to me.
I want it to go
away. Therefore, I rewrite A.py as:
import math as _math
def f(): pass
. Now, Idle will only offer the completion "A.f".
So, I sometimes use this "import math as _math" style. But then,
it is simpler for me to /always/ use this style; after all: you
can't know whether someone eventually will import your module!
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.
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']
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.
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']
Sysop: | Tetrazocine |
---|---|
Location: | Melbourne, VIC, Australia |
Users: | 6 |
Nodes: | 8 (0 / 8) |
Uptime: | 44:44:16 |
Calls: | 45 |
Files: | 21,492 |
Messages: | 63,459 |